-
Notifications
You must be signed in to change notification settings - Fork 113
Searchpath free problems #27
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
Conversation
Be more careful when freeing sections. Fixes double free inside cfg_free() at the end of tests/searchpath.c
Good catch, I'll analyze it further for the v2.9 release cycle! Would be awesome to set up Travis-CI with automatic static code analysis with Coverity. That way we could get a better overview of memory handling issues like this. Must talk to @martinh about this later, maybe he can spare a few clock cycles of his time to do some clicking in those tools for us :) |
I am also encountering an issue with freeing memory in the searchpath test. It causes infinite recursion in cfg_free_searchpath, making the stack overflow in MSYS2. Here is a trace I made with printf calls showing the problem; you can see that one searchpath (0000000000396f50) gets freed twice.
The tests pass in Linux. Running the tests under Linux with Valgrind shows that there might be some leaks, but I'm not quite sure how to interpret the repetitive output from Valgrind. Just to be clear, everything I am talking about here applies to my slightly-modified version of the current martinh/libconfuse master branch. I have not tried the patch from @peda-r yet. |
I haven't looked carefully at the code, but this pull request from @peda-r does make searchpath.exe pass under Windows, so 👍 . It does not have a noticeable effect on the Valgrind output in Linux. |
I switched back to the martinh version of libconfuse (e5b5082), and I can see that libconfuse is definitely confused about freeing searchpaths, even in Linux. I added a printf statement to static void cfg_free_searchpath(cfg_searchpath_t* p)
{
if (p)
{
printf("Freeing searchpath %p\n", p);
cfg_free_searchpath(p->next);
free(p);
}
} When I run
The test passes somehow, but it's clear that the library is severely malfunctioning, and I would not recommend releasing it in this state. |
Thank you for the analysis @DavidEGrayson, you just convinced me this PR needs to be merged for the v2.8 release 😃 |
Sections do not have a deep copy of the searchpath, so we must be more careful when freeing sections. This patch fixes a double free inside cfg_free() at the end of tests/searchpath.c Also frees the directory when freeing a seachpath entry. Signed-off-by: Peter Rosin <peda@lysator.liu.se> Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Squashed the two commits into one and updated the commit message slightly. |
Great, thanks! |
I wrote a test for the section removal code in that other pull request and ran the testsuite for the first time and noticed a crash in the searchpath test. Incidentally, it turned out to be related to section removal...
I came up with fixes for two memory handling problems...
Cheers,
Peter