From: Jonathan Nieder Date: Tue, 10 Aug 2010 03:32:11 +0000 (-0500) Subject: write-tree: Avoid leak when index refers to an invalid object X-Git-Tag: v1.7.2.3~19^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b6b56aceb85fe05dc681ac7ee1249e6b6e26e957;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/cache-tree.c b/cache-tree.c index d91743775..c60cf9140 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 */