Skip to content

Fix a memory leak in odb_otype_fast()#4987

Merged
pks-t merged 1 commit intolibgit2:masterfrom
lhchavez:fix-odb_otype_fast-leak
Feb 21, 2019
Merged

Fix a memory leak in odb_otype_fast()#4987
pks-t merged 1 commit intolibgit2:masterfrom
lhchavez:fix-odb_otype_fast-leak

Conversation

@lhchavez
Copy link
Copy Markdown
Contributor

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

@lhchavez
Copy link
Copy Markdown
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!).

Comment thread tests/odb/mixed.c
Comment thread src/odb.c

if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
*type_p = object->cached.type;
git_odb_object_free(object);
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.

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().
@lhchavez lhchavez force-pushed the fix-odb_otype_fast-leak branch from bda2b96 to 6b3730d Compare February 20, 2019 14:31
@pks-t pks-t merged commit 6eb4947 into libgit2:master Feb 21, 2019
@pks-t
Copy link
Copy Markdown
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.

2 participants