Commit 2d9426b0 authored by Stefan Beller's avatar Stefan Beller Committed by Junio C Hamano

read-cache: free cache entry in add_to_index in case of early return

This frees `ce` would be leaking in the error path.

Additionally a free is moved towards the return. This helps code
readability as we often have this pattern of freeing resources just
before return/exit and not in between the code.
Signed-off-by: Stefan Beller's avatarStefan Beller <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent fd2014d4
......@@ -681,15 +681,18 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
alias = index_file_exists(istate, ce->name, ce_namelen(ce), ignore_case);
if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
/* Nothing changed, really */
if (!S_ISGITLINK(alias->ce_mode))
alias->ce_flags |= CE_ADDED;
return 0;
if (!intent_only) {
if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT))
if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT)) {
return error("unable to index file %s", path);
} else
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment