summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2015-02-17 10:06:14 -0800
committerJunio C Hamano <gitster@pobox.com>2015-02-17 10:42:43 -0800
commitbc1c2caa7397e7e462f0cc7631a40f6e7cd480ab (patch)
tree8ab424539192646dad2e9cbe4b6db3cd77f7e11c
parent64a03e970ab3ef0ce45d6bd3c1de1bff1de2beee (diff)
downloadgit-bc1c2caa7397e7e462f0cc7631a40f6e7cd480ab.tar.gz
read-cache.c: free cache entry when refreshing failssb/plug-leak-in-make-cache-entry
This fixes a memory leak when building the cache entries as refresh_cache_entry may decide to return NULL, but it does not free the cache entry structure which was passed in as an argument. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--read-cache.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c
index ee07cd610a..565546db50 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -701,7 +701,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
unsigned int refresh_options)
{
int size, len;
- struct cache_entry *ce;
+ struct cache_entry *ce, *ret;
if (!verify_path(path)) {
error("Invalid path '%s'", path);
@@ -718,7 +718,13 @@ struct cache_entry *make_cache_entry(unsigned int mode,
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
- return refresh_cache_entry(ce, refresh_options);
+ ret = refresh_cache_entry(ce, refresh_options);
+ if (!ret) {
+ free(ce);
+ return NULL;
+ } else {
+ return ret;
+ }
}
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)