-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix a _very_ improbable memory leak in git_odb_new() #4988
Fix a _very_ improbable memory leak in git_odb_new() #4988
Conversation
This change fixes a mostly theoretical memory leak in got_odb_new() that can only manifest if git_cache_init() fails due to running out of memory or not being able to acquire its lock.
dd2929b
to
dd45539
Compare
Unfortunately I was not able to come up with a test for this :( |
/rebuild |
Okay, @lhchavez, I started to rebuild this pull request as build #1512. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's hard to come up with tests for OOM situation. We have thought iabout creating a test allocator that will create an artificial OOM situation after having allocated n
bytes. That would make it possible to test your fix, even though it would need to be quite intimate with the implementation of the system under test.
Anyway, this fix looks good to me. Thanks for your PR!
return -1; | ||
} | ||
if (git_vector_init(&db->backends, 4, backend_sort_cmp) < 0) { | ||
git_cache_free(&db->own_cache); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more instance of a misnamed _free
function. git_cache_free
does not free the cache struct itself, but only disposes its contents. So this change is correct.
I'll create a PR that renames this function to git_cache_dispose
, as it should be called
This change fixes a mostly theoretical memory leak in got_odb_new()
that can only manifest if git_cache_init() fails due to running out of
memory or not being able to acquire its lock.