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>

Johannes Schindelin committed May 4, 2017 at 15:57 UTC 43e61e715283ba3e6cfe5ebf9e831e1d96cec399
1 file changed +3 -2
builtin/mktree.c
+3 -2
@@ -72,7 +72,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
72 unsigned mode;
73 enum object_type mode_type; /* object type derived from mode */
74 enum object_type obj_type; /* object type derived from sha */
75 - char *path;
75 + char *path, *to_free = NULL;
76 unsigned char sha1[20];
77
78 ptr = buf;
@@ -102,7 +102,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
102 struct strbuf p_uq = STRBUF_INIT;
103 if (unquote_c_style(&p_uq, path, NULL))
104 die("invalid quoting");
105 - path = strbuf_detach(&p_uq, NULL);
105 + path = to_free = strbuf_detach(&p_uq, NULL);
106 }
107
108 /*
@@ -136,6 +136,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
136 }
137
138 append_to_tree(mode, sha1, path);
139 + free(to_free);
140 }
141
142 int cmd_mktree(int ac, const char **av, const char *prefix)