update-index: fix cache entry leak in add_one_file()
When we fail to add the cache entry to the index, we end up just leaking the struct. We should follow the pattern of the early-return above and free it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 5, 2017 at 09:04 UTC
baddc96b2cbf66fdcde87509392dc8da6a77f452
1 file changed
+3
-1
builtin/update-index.c
+3
-1
@@ -287,8 +287,10 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
287
}
288
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
289
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
290
- if (add_cache_entry(ce, option))
290
+ if (add_cache_entry(ce, option)) {
291
+ free(ce);
292
return error("%s: cannot add to the index - missing --add option?", path);
293
+ }
294
return 0;
295
}
296