summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2015-03-23 17:57:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-03-23 18:12:59 (GMT)
commit915e44c6357f3bd9d5fa498a201872c4367302d3 (patch)
tree5a266853f74dff3c34666f005719bd34bb423a35 /read-cache.c
parent067178ed8a7822e6bc88ad606b707fc33658e6fc (diff)
downloadgit-915e44c6357f3bd9d5fa498a201872c4367302d3.zip
git-915e44c6357f3bd9d5fa498a201872c4367302d3.tar.gz
git-915e44c6357f3bd9d5fa498a201872c4367302d3.tar.bz2
read-cache: fix memleak
`ce` is allocated in make_cache_entry and should be freed if it is not used any more. refresh_cache_entry as a wrapper around refresh_cache_ent will either return - the `ce` given as the parameter, when it was up-to-date; - a new updated cache entry which is allocated to new memory; or - a NULL when refreshing failed. In the latter two cases, the original cache-entry `ce` is not used and needs to be freed. The rule can be expressed as "if the return value from refresh is different from the original ce, ce is no longer used." Helped-by: Junio C Hamano <gitster@pobox.com> 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.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/read-cache.c b/read-cache.c
index 5b922fd..0052b72 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -748,12 +748,9 @@ struct cache_entry *make_cache_entry(unsigned int mode,
ce->ce_mode = create_ce_mode(mode);
ret = refresh_cache_entry(ce, refresh_options);
- if (!ret) {
+ if (ret != ce)
free(ce);
- return NULL;
- } else {
- return ret;
- }
+ return ret;
}
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)