From: Jeff King Date: Tue, 5 Sep 2017 13:04:14 +0000 (-0400) Subject: update-index: fix cache entry leak in add_one_file() X-Git-Tag: v2.15.0-rc0~83^2~6 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/baddc96b2cbf66fdcde87509392dc8da6a77f452 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/update-index.c b/builtin/update-index.c index d562f2ec69..d955cd56b3 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -287,8 +287,10 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len } option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; - if (add_cache_entry(ce, option)) + if (add_cache_entry(ce, option)) { + free(ce); return error("%s: cannot add to the index - missing --add option?", path); + } return 0; }