I'm running into what I think is a memory corruption issue which is happening in cmd_ln_parse_file_r() in cmd_ln.c for sphinxbase (prea5). I've confirmed that the config object passed to the method was created and allocated correctly, but during the argument parsing in sphinxbase the ht member suddenly starts losing objects.
This is my current trace and setup:
Rust wrapper successfully allocates and sets up the config (1)
Rust wrapper calls ps_init() in pocketsphinx.c with a valid config pointer (2)
ps_init() passes the config pointer to ps_reinit()
ps_reinit() sets the config member of the ps object and sets up default arguments by calling ps_expand_model_config()
ps_expand_model_config() looks for feat.params in the acoustic model dir by calling cmd_ln_parse_file_r()
Up until this point, my debugging shows that ps->config->ht still contains all of its data (as expected.) Once it touches cmd_ln_parse_file_r() in cmd_ln.c in sphinxbase, hashtable elements start disappearing. Specifically, it occurs somewhere in the do-while loop, possibly related to the ckd_salloc() usage.
Commenting out the code under /* Add the string to the list of arguments */ causes ps->config->ht to not lose its data and pocketsphinx continues as expected.
I'm relatively new to Rust, so perhaps the library/crate is doing something it's not supposed to. Any help would be greatly appreciated though, as I can't init pocketsphinx without my "patch."
-J
Last edit: Josh Kross 2016-09-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, its a bug in sphinxbase. Basically it assumes that config arguments are not deallocated, while rust seems the only language that deallocates static strings. So when you use "-dict" it is freed and memory is corrupted. It needs some thinking on how to fix it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm running into what I think is a memory corruption issue which is happening in
cmd_ln_parse_file_r()
in cmd_ln.c for sphinxbase (prea5). I've confirmed that the config object passed to the method was created and allocated correctly, but during the argument parsing in sphinxbase theht
member suddenly starts losing objects.This is my current trace and setup:
ps_init()
in pocketsphinx.c with a valid config pointer (2)ps_init()
passes the config pointer tops_reinit()
ps_reinit()
sets the config member of theps
object and sets up default arguments by callingps_expand_model_config()
ps_expand_model_config()
looks for feat.params in the acoustic model dir by callingcmd_ln_parse_file_r()
Up until this point, my debugging shows that
ps->config->ht
still contains all of its data (as expected.) Once it touchescmd_ln_parse_file_r()
in cmd_ln.c in sphinxbase, hashtable elements start disappearing. Specifically, it occurs somewhere in thedo-while
loop, possibly related to theckd_salloc()
usage.Commenting out the code under
/* Add the string to the list of arguments */
causesps->config->ht
to not lose its data and pocketsphinx continues as expected.I'm relatively new to Rust, so perhaps the library/crate is doing something it's not supposed to. Any help would be greatly appreciated though, as I can't init pocketsphinx without my "patch."
-J
Last edit: Josh Kross 2016-09-06
Mystery indeed. I can reproduce it but not sure about the reason yet.
Ok, its a bug in sphinxbase. Basically it assumes that config arguments are not deallocated, while rust seems the only language that deallocates static strings. So when you use "-dict" it is freed and memory is corrupted. It needs some thinking on how to fix it.
Ok, this issue has been just fixed in trunk. Please update sphinxbase and try again, it should work.
Thanks, looks like it's working now! Will update if I run into any more Rust-specific bugs though :)