diff options
author | Stefan Beller <sbeller@google.com> | 2015-03-20 17:28:00 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-03-22 12:11:25 -0700 |
commit | 2d9426b049335c1a39be7ea7416094e944bfe63c (patch) | |
tree | 804bff73de68211cdea205d565cbd63abf9bf4a4 /read-cache.c | |
parent | fd2014d42b3a4fb865d99e9a7943caa08082cada (diff) | |
download | git-2d9426b049335c1a39be7ea7416094e944bfe63c.tar.gz |
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 <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c index 8d71860f69..60abec6055 100644 --- a/read-cache.c +++ b/read-cache.c @@ -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 */ - free(ce); if (!S_ISGITLINK(alias->ce_mode)) ce_mark_uptodate(alias); alias->ce_flags |= CE_ADDED; + + free(ce); 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)) { + free(ce); return error("unable to index file %s", path); + } } else set_object_name_for_intent_to_add_entry(ce); |