add_to_index(): free unused cache-entry

We allocate a cache-entry pretty early in the function and then decide either not to do anything when we are pretending to add, or add it and then get an error (another possibility is obviously to succeed). When pretending or failing to add, we forgot to free the cache-entry. Noticed during a discussion on Stefan's patch to change the coding style without fixing the issue ;-) Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 23, 2015 at 10:58 UTC 067178ed8a7822e6bc88ad606b707fc33658e6fc
1 file changed +5 -3
read-cache.c
+5 -3
@@ -707,9 +707,11 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
707 ce->ce_mode == alias->ce_mode);
708
709 if (pretend)
710 - ;
711 - else if (add_index_entry(istate, ce, add_option))
712 - return error("unable to add %s to index",path);
710 + free(ce);
711 + else if (add_index_entry(istate, ce, add_option)) {
712 + free(ce);
713 + return error("unable to add %s to index", path);
714 + }
715 if (verbose && !was_same)
716 printf("add '%s'\n", path);
717 return 0;