Skip to content

Fix a _very_ improbable memory leak in git_odb_new()#4988

Merged
pks-t merged 1 commit intolibgit2:masterfrom
lhchavez:fix-improbable-odb-initialization-leak
Feb 20, 2019
Merged

Fix a _very_ improbable memory leak in git_odb_new()#4988
pks-t merged 1 commit intolibgit2:masterfrom
lhchavez:fix-improbable-odb-initialization-leak

Conversation

@lhchavez
Copy link
Copy Markdown
Contributor

@lhchavez lhchavez commented Feb 17, 2019

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.

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.
@lhchavez lhchavez force-pushed the fix-improbable-odb-initialization-leak branch from dd2929b to dd45539 Compare February 17, 2019 06:09
@lhchavez
Copy link
Copy Markdown
Contributor Author

Unfortunately I was not able to come up with a test for this :(

@lhchavez
Copy link
Copy Markdown
Contributor Author

/rebuild

@libgit2-azure-pipelines
Copy link
Copy Markdown

Okay, @lhchavez, I started to rebuild this pull request as build #1512.

Copy link
Copy Markdown
Member

@pks-t pks-t left a 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);
Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants