Skip to content

Commit

Permalink
write-tree: Avoid leak when index refers to an invalid object
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jrn authored and gitster committed Aug 11, 2010
1 parent 1ce584b commit b6b56ac
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit b6b56ac

Please sign in to comment.