Skip to content

Commit baddc96

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe6a01a commit baddc96

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/update-index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
287287
}
288288
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
289289
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);
291292
return error("%s: cannot add to the index - missing --add option?", path);
293+
}
292294
return 0;
293295
}
294296

0 commit comments

Comments
 (0)