diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-03-27 13:02:32 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-03-27 13:02:32 -0700 |
commit | 553c622b685f0a7a83c77617377f08019d76c682 (patch) | |
tree | 59a6165ca81d3355fe9279a929563fd1c0b91d55 /read-cache.c | |
parent | Git 2.4.0-rc0 (diff) | |
parent | http: release the memory of a http pack request as well (diff) | |
download | tgif-553c622b685f0a7a83c77617377f08019d76c682.tar.xz |
Merge branch 'sb/leaks'
* sb/leaks:
http: release the memory of a http pack request as well
read-cache: fix memleak
add_to_index(): free unused cache-entry
commit.c: fix a memory leak
http-push: remove unneeded cleanup
merge-recursive: fix memleaks
merge-blobs.c: fix a memleak
builtin/apply.c: fix a memleak
update-index: fix a memleak
read-cache: free cache entry in add_to_index in case of early return
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/read-cache.c b/read-cache.c index 1bf78a445f..36ff89f29e 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); @@ -704,9 +707,11 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ce->ce_mode == alias->ce_mode); if (pretend) - ; - else if (add_index_entry(istate, ce, add_option)) - return error("unable to add %s to index",path); + free(ce); + else if (add_index_entry(istate, ce, add_option)) { + free(ce); + return error("unable to add %s to index", path); + } if (verbose && !was_same) printf("add '%s'\n", path); return 0; @@ -743,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) |