@matheusbsbs / matheus-bagliano / commits / b6b56aceb8
Fork 0

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>

Jonathan Nieder committed Aug 9, 2010 at 22:32 UTC b6b56aceb85fe05dc681ac7ee1249e6b6e26e957
1 file changed +3 -1
cache-tree.c
+3 -1
@@ -328,9 +328,11 @@ static int update_one(struct cache_tree *it,
328 mode = ce->ce_mode;
329 entlen = pathlen - baselen;
330 }
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);
333 return error("invalid object %06o %s for '%.*s'",
334 mode, sha1_to_hex(sha1), entlen+baselen, path);
335 + }
336
337 if (ce->ce_flags & CE_REMOVE)
338 continue; /* entry being removed */