summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-02-25 15:40:21 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-02-25 15:40:21 -0800
commitb4e8fefc7f4c98769172c1ecb5bc10dab637cc5b (patch)
tree660336c553b42afe766a803970128c240a4a08b4
parentMerge branch 'mh/transport-capabilities' (diff)
parentread-cache.c: free cache entry when refreshing fails (diff)
downloadtgif-b4e8fefc7f4c98769172c1ecb5bc10dab637cc5b.tar.xz
Merge branch 'sb/plug-leak-in-make-cache-entry'
"update-index --refresh" used to leak when an entry cannot be refreshed for whatever reason. * sb/plug-leak-in-make-cache-entry: read-cache.c: free cache entry when refreshing fails
-rw-r--r--read-cache.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c
index 9cff715d6b..8d71860f69 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -725,7 +725,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);
@@ -742,7 +742,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)