Merge branch 'sb/leaks'
authorJunio C Hamano <gitster@pobox.com>
Fri, 27 Mar 2015 20:02:32 +0000 (13:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Mar 2015 20:02:32 +0000 (13:02 -0700)
* 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

builtin/apply.c
builtin/commit.c
builtin/update-index.c
http-push.c
http.c
merge-blobs.c
merge-recursive.c
read-cache.c
index 65b97eee69d4814bf80f87b1fd6857b8ed80cb90..0769b09287b2bcf6b3f85ff503a396fa245c31a0 100644 (file)
@@ -2776,7 +2776,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                default:
                        if (apply_verbosely)
                                error(_("invalid start of line: '%c'"), first);
-                       return -1;
+                       applied_pos = -1;
+                       goto out;
                }
                if (added_blank_line) {
                        if (!new_blank_lines_at_end)
@@ -2915,6 +2916,7 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                              (int)(old - oldlines), oldlines);
        }
 
+out:
        free(oldlines);
        strbuf_release(&newlines);
        free(preimage.line_allocated);
index 961e467242747dac07aa6f5e619e2d1a50570b06..da79ac4bc7a7247017e2f952b35642a1976c8101 100644 (file)
@@ -229,7 +229,7 @@ static int commit_index_files(void)
 static int list_paths(struct string_list *list, const char *with_tree,
                      const char *prefix, const struct pathspec *pattern)
 {
-       int i;
+       int i, ret;
        char *m;
 
        if (!pattern->nr)
@@ -256,7 +256,9 @@ static int list_paths(struct string_list *list, const char *with_tree,
                        item->util = item; /* better a valid pointer than a fake one */
        }
 
-       return report_path_error(m, pattern, prefix);
+       ret = report_path_error(m, pattern, prefix);
+       free(m);
+       return ret;
 }
 
 static void add_remove_files(struct string_list *list)
index 587898624c0550749a9a241e2742785f20ec1bd5..6271b54adc24c8765ca0b179faf53f6af86dc630 100644 (file)
@@ -584,6 +584,7 @@ static int do_reupdate(int ac, const char **av,
                path = xstrdup(ce->name);
                update_one(path);
                free(path);
+               free(old);
                if (save_nr != active_nr)
                        goto redo;
        }
index bfb1c9605b46e8308e91a80c38643ea920cd4d1b..c98dad23dfd86875209295fadda39c1f1b4f5224 100644 (file)
@@ -316,7 +316,6 @@ static void start_fetch_packed(struct transfer_request *request)
 
        preq = new_http_pack_request(target, repo->url);
        if (preq == NULL) {
-               release_http_pack_request(preq);
                repo->can_update_info_refs = 0;
                return;
        }
diff --git a/http.c b/http.c
index 9c825afefdda70b8f8ccda0b9ed06e5d54333a50..4b179f6fc8f29c1683b187393203d20f95d29157 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1462,6 +1462,7 @@ void release_http_pack_request(struct http_pack_request *preq)
        }
        preq->slot = NULL;
        free(preq->url);
+       free(preq);
 }
 
 int finish_http_pack_request(struct http_pack_request *preq)
index 57211bccb7d0a5aad8538906bcb2f4ad2900f008..7abb894c684d1ff7bc26b30ffa41597451750f20 100644 (file)
@@ -14,8 +14,10 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
        buf = read_sha1_file(obj->object.sha1, &type, &size);
        if (!buf)
                return -1;
-       if (type != OBJ_BLOB)
+       if (type != OBJ_BLOB) {
+               free(buf);
                return -1;
+       }
        f->ptr = buf;
        f->size = size;
        return 0;
index 771f5e21b09aac6976297b8a6e9028f90787a764..1c9c30db6cbf229a2f836113c04bb980340ce7eb 100644 (file)
@@ -1858,6 +1858,9 @@ int merge_trees(struct merge_options *o,
                string_list_clear(re_head, 0);
                string_list_clear(entries, 1);
 
+               free(re_merge);
+               free(re_head);
+               free(entries);
        }
        else
                clean = 1;
index 1bf78a445fc9e397d1e8c7d91867b093bbcea775..36ff89f29e5f56a5b3dcfd803f12cd139295b8b8 100644 (file)
@@ -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)