write-tree: Avoid leak when index refers to an invalid object

Noticed by valgrind during test t0000.35 “writing this tree without

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>
This commit is contained in:
Jonathan Nieder 2010-08-09 22:32:11 -05:00 committed by Junio C Hamano
parent 1ce584b058
commit b6b56aceb8
1 changed files with 3 additions and 1 deletions

View File

@ -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)) {
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 */