Skip to content

Commit

Permalink
add_to_index(): free unused cache-entry
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Mar 23, 2015
1 parent 5d0b9bf commit 067178e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,11 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
ce->ce_mode == alias->ce_mode);

if (pretend)
;
else if (add_index_entry(istate, ce, add_option))
return error("unable to add %s to index",path);
free(ce);
else if (add_index_entry(istate, ce, add_option)) {
free(ce);
return error("unable to add %s to index", path);
}
if (verbose && !was_same)
printf("add '%s'\n", path);
return 0;
Expand Down

0 comments on commit 067178e

Please sign in to comment.