summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-08-10 03:32:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-08-11 16:58:38 (GMT)
commitb6b56aceb85fe05dc681ac7ee1249e6b6e26e957 (patch)
treece5d371dceacde2e2f3d686669c8127c6d83c319 /cache-tree.c
parent1ce584b05843dfa8b0fe31ed3d75bddf1c29c4e0 (diff)
downloadgit-b6b56aceb85fe05dc681ac7ee1249e6b6e26e957.zip
git-b6b56aceb85fe05dc681ac7ee1249e6b6e26e957.tar.gz
git-b6b56aceb85fe05dc681ac7ee1249e6b6e26e957.tar.bz2
write-tree: Avoid leak when index refers to an invalid object
Noticed by valgrind during test t0000.35 “writing this tree without --missing-ok”. Even in the cherry-pick foo..bar code path, such an error is the end of the line. But maybe some day an interactive porcelain will want to link to libgit, making this matter. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/cache-tree.c b/cache-tree.c
index d917437..c60cf91 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -328,9 +328,11 @@ static int update_one(struct cache_tree *it,
mode = ce->ce_mode;
entlen = pathlen - baselen;
}
- if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
+ if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
+ strbuf_release(&buffer);
return error("invalid object %06o %s for '%.*s'",
mode, sha1_to_hex(sha1), entlen+baselen, path);
+ }
if (ce->ce_flags & CE_REMOVE)
continue; /* entry being removed */