unifex seg fault on handle_destroy_state
Hi, i'm implementing g772.1 decoder/encoder plugin and have issue with handle_destroy state.
I've taken freeswitch g7221 implementation(https://github.com/traviscross/freeswitch/tree/master/libs/libg722_1/src).
I have the following state:
and added following handle_destroy_state callback:
but it causes segmentation fault. g7221_1_decode_release calls free on passed pointer. Implementation of g722_1_decode_release:
Is it state freed by unifex itself?
4 Replies
I hope this is right place to post unifex questions, since Membrane framework is the owner of unifex.
Are you sure that you have initialized the state properly (assinging a NULL on initialization or making sure that the state gets initialized before being freed)?
Operating with state should have the following steps:
1.
unifex_alloc_state
to allocate a state
2. unifex_release_state
in the same initialization function just before returning from the init function to ensure the state gets released when the last elixir's reference vanishes
3. do any internal cleanup inside of handle_destroy_state
, you don't have to release the unifex state inside of the callback, just cleanup after the g722My bad. I made mistake on state initialization, made changes to create:
and now is working correctly. I'm new to C programming, reread about pointers and it seems clear for me now.
but may be I fixed it incorrectly, thanks for directions btw
final fix:
If I put NULL as initial parameter - g7221_1_decode_init initializes memory itself and it is correctly freed on destroy
glad it works 🙂