Fix a _very_ improbable memory leak in git_odb_new()#4988
Fix a _very_ improbable memory leak in git_odb_new()#4988pks-t merged 1 commit intolibgit2:masterfrom
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. |
pks-t
left a comment
There was a problem hiding this comment.
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.
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.