vnmakarov / yaep

Yet Another Earley Parser
Other
137 stars 14 forks source link

Memory leak in yaep_free_grammar() #10

Closed TheCount closed 6 years ago

TheCount commented 6 years ago

The following very simple program:

#include<yaep.h>

int main( void ) {
        struct grammar * g1 = yaep_create_grammar();
        yaep_free_grammar( g1 );
        struct grammar * g2 = yaep_create_grammar();
        yaep_free_grammar( g2 );
}

leaks memory. It's not quite clear to me what happens here. Apparently, yaep_free_grammar() deallocates some substructures of struct grammar, but not the memory for struct grammar itself (the first two lines of main() are sufficient to expose this problem). But in addition, yaep_create_grammar() and yaep_free_grammar() seem to handle a global grammar object (which kind of defeats the purpose of having multiple grammars) and thus some memory becomes lost permanently.

TheCount commented 6 years ago

Pull request #11 fixes the memory leak. The handling of a global object is a different problem. I'll open a separate issue for that. This issue can then be closed once the pull request is merged.