]> asedeno.scripts.mit.edu Git - git.git/commitdiff
write-tree: Avoid leak when index refers to an invalid object
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 10 Aug 2010 03:32:11 +0000 (22:32 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Aug 2010 16:58:38 +0000 (09:58 -0700)
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>
cache-tree.c

index d91743775dfbe98d99d8ab25a270af320c8b984e..c60cf9140dd18254886ea14de763738630f95973 100644 (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)) {
+                       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 */