Skip to content
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

Merged

Conversation

lhchavez
Copy link
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
Contributor Author

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

@lhchavez
Copy link
Contributor Author

/rebuild

@libgit2-azure-pipelines
Copy link

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

Copy link
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
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.

None yet

2 participants