Menu

Memory corruption in cmd_ln.c (sphinxbase, pocketsphinx)

Help
Josh Kross
2016-09-06
2016-09-08
  • Josh Kross

    Josh Kross - 2016-09-06

    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 the ht member suddenly starts losing objects.

    This is my current trace and setup:

    1. Rust wrapper successfully allocates and sets up the config (1)
    2. Rust wrapper calls ps_init() in pocketsphinx.c with a valid config pointer (2)
    3. ps_init() passes the config pointer to ps_reinit()
    4. ps_reinit() sets the config member of the ps object and sets up default arguments by calling ps_expand_model_config()
    5. 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
    • Nickolay V. Shmyrev

      Mystery indeed. I can reproduce it but not sure about the reason yet.

       
      • Nickolay V. Shmyrev

        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.

         
        • Nickolay V. Shmyrev

          Ok, this issue has been just fixed in trunk. Please update sphinxbase and try again, it should work.

           
          • Josh Kross

            Josh Kross - 2016-09-08

            Thanks, looks like it's working now! Will update if I run into any more Rust-specific bugs though :)

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.