mktree: plug memory leaks reported by Coverity

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin 2017-05-04 15:57:28 +02:00 committed by Junio C Hamano
parent 077a34e0b9
commit 43e61e7152

View File

@ -72,7 +72,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
unsigned mode; unsigned mode;
enum object_type mode_type; /* object type derived from mode */ enum object_type mode_type; /* object type derived from mode */
enum object_type obj_type; /* object type derived from sha */ enum object_type obj_type; /* object type derived from sha */
char *path; char *path, *to_free = NULL;
unsigned char sha1[20]; unsigned char sha1[20];
ptr = buf; ptr = buf;
@ -102,7 +102,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
struct strbuf p_uq = STRBUF_INIT; struct strbuf p_uq = STRBUF_INIT;
if (unquote_c_style(&p_uq, path, NULL)) if (unquote_c_style(&p_uq, path, NULL))
die("invalid quoting"); die("invalid quoting");
path = strbuf_detach(&p_uq, NULL); path = to_free = strbuf_detach(&p_uq, NULL);
} }
/* /*
@ -136,6 +136,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
} }
append_to_tree(mode, sha1, path); append_to_tree(mode, sha1, path);
free(to_free);
} }
int cmd_mktree(int ac, const char **av, const char *prefix) int cmd_mktree(int ac, const char **av, const char *prefix)