Skip to content

Commit b6b56ac

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ce584b commit b6b56ac

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cache-tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ static int update_one(struct cache_tree *it,
328328
mode = ce->ce_mode;
329329
entlen = pathlen - baselen;
330330
}
331-
if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
331+
if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
332+
strbuf_release(&buffer);
332333
return error("invalid object %06o %s for '%.*s'",
333334
mode, sha1_to_hex(sha1), entlen+baselen, path);
335+
}
334336

335337
if (ce->ce_flags & CE_REMOVE)
336338
continue; /* entry being removed */

0 commit comments

Comments
 (0)