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 memory leak in odb_otype_fast() #4987

Merged
merged 1 commit into from
Feb 21, 2019

Conversation

lhchavez
Copy link
Contributor

This change frees a copy of a cached object in odb_otype_fast().

@lhchavez
Copy link
Contributor Author

Found an uncovered codepath while hunting for an unrelated memory leak.

Unfortunately the test only makes sense if #3918 is merged and ASan is enabled (meaning that the fix can be missing and it would still pass!).

tests/odb/mixed.c Show resolved Hide resolved
@@ -1124,6 +1124,7 @@ static int odb_otype_fast(git_object_t *type_p, git_odb *db, const git_oid *id)

if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
*type_p = object->cached.type;
git_odb_object_free(object);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. git_cache_get_raw calls cache_get, which in turn calls git_cached_obj_incref on the returned entry. So it's the right thing to free the object here.

This change frees a copy of a cached object in odb_otype_fast().
@pks-t pks-t merged commit 6eb4947 into libgit2:master Feb 21, 2019
@pks-t
Copy link
Member

pks-t commented Feb 21, 2019

Thanks a lot, @lhchavez!

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