New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak - failure to free lexer allocated memory. #21
Comments
This is still present in 3.0 and current git version. ==2644== 8 bytes in 1 blocks are still reachable in loss record 1 of 1 |
Great! Could you prepare a pull request? |
Sorry, I don't have a fix (yet, anyway). I'll try what nadav2051 proposed and if it works, i'll share it. |
@brankod Looking forward to it! 😃 |
I looked into this and I'm not sure there is an easy fix. As nadav2051 reports, calling cfg_yylex_destroy() after all parsing is done, frees yy_buffer_stack. I hoped this could be added to cfg_free, but after this change tests that call cfg_free/cfgf_parse multiple times fail. I'll scratch my head a bit more, why. |
Thanks, I've noticed this too. Don't worry, I'll look into it during the weekend ☺👍 |
I was thinking, one solution is to simply add a public function that calls cfg_yylex_destroy(), possibly marked with attribute((destructor)). It is really unimportant leak most users probably don't care about, but some of us like too see valgrind report "no leaks possible". :) What do you think? |
I was actually thinking the same thing, so in my tree I've added a However, as I've been going through regressions in test cases, with the previous idea for a fix, I noticed there are a few annoying leaks that are aggregated every time |
This patch, and the ones immediately preceding it, fix issue libconfuse#21. The original intention was to add a cfg_exit() to call cfg_yylex_destroy(), and if someone reports regressions due to this commit, that is likely the best alternative solution. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch, and the ones immediately preceding it, fix issue libconfuse#21. The original intention was to add a cfg_exit() to call cfg_yylex_destroy(), and if someone reports regressions due to this commit, that is likely the best alternative solution. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Turned out to be quite a large change set to address all the memory leaks I encountered while fixing this. Fortunately the changes made do not introduce any new API, It would be most helpful to get feedback/review of pull request #75 ... if you do, please use the GitHub review feature (top right corner of the PR). |
Fix #21: Refactor of lexer and fix memory leaks
Hey, I've stumbled across a possible memory leak - not sure whether it's intentional or not -
It appears as if the free_cfg() library function neglects to free the yy_buffer_stack global variable.
I externed the cfg_yylex_destroy() function and used it straight after calling to free_cfg() and the memory leak was gone.
The text was updated successfully, but these errors were encountered: