summaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-12-12 09:36:15 +0100
committerPatrick Steinhardt <ps@pks.im>2016-12-12 09:45:07 +0100
commitff5eea06a98182697f16d1335ee331cd8cd1b90c (patch)
tree7df75d7c133b45fa391948a2af38c89be37805b1 /src/pack.c
parent8339c66068c8e964f8bf1eca10745db730bf62fa (diff)
downloadlibgit2-ff5eea06a98182697f16d1335ee331cd8cd1b90c.tar.gz
pack: dereference cached pack entry on error
When trying to uncompress deltas in a packfile's delta chain, we try to add object bases to the packfile cache, subsequently decrementing its reference count if it has been added successfully. This may lead to a mismatched reference count in the case where we exit the loop early due to an encountered error. Fix the issue by decrementing the reference count in error cleanup.
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/pack.c b/src/pack.c
index 2ee0c60e4..16e82a92b 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -757,8 +757,11 @@ int git_packfile_unpack(
}
cleanup:
- if (error < 0)
+ if (error < 0) {
git__free(obj->data);
+ if (cached)
+ git_atomic_dec(&cached->refcount);
+ }
if (elem)
*obj_offset = curpos;