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

1  2 
http-push.c
read-cache.c
diff --combined http-push.c
index bfb1c9605b46e8308e91a80c38643ea920cd4d1b,9469684e9c9b68f9961352a2fcd046891282c8ac..c98dad23dfd86875209295fadda39c1f1b4f5224
@@@ -316,7 -316,6 +316,6 @@@ static void start_fetch_packed(struct t
  
        preq = new_http_pack_request(target, repo->url);
        if (preq == NULL) {
-               release_http_pack_request(preq);
                repo->can_update_info_refs = 0;
                return;
        }
@@@ -365,6 -364,7 +364,6 @@@ static void start_put(struct transfer_r
        hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
  
        /* Set it up */
 -      memset(&stream, 0, sizeof(stream));
        git_deflate_init(&stream, zlib_compression_level);
        size = git_deflate_bound(&stream, len + hdrlen);
        strbuf_init(&request->buffer.buf, size);
diff --combined read-cache.c
index 1bf78a445fc9e397d1e8c7d91867b093bbcea775,0052b72d9c230d937fc66633358e7aefbe379042..36ff89f29e5f56a5b3dcfd803f12cd139295b8b8
@@@ -681,15 -681,18 +681,18 @@@ int add_to_index(struct index_state *is
        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);
  
                    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 +748,9 @@@ struct cache_entry *make_cache_entry(un
        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)
@@@ -1486,25 -1488,18 +1488,25 @@@ static struct cache_entry *create_from_
        return ce;
  }
  
 -static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce)
 +static void check_ce_order(struct index_state *istate)
  {
 -      int name_compare = strcmp(ce->name, next_ce->name);
 -      if (0 < name_compare)
 -              die("unordered stage entries in index");
 -      if (!name_compare) {
 -              if (!ce_stage(ce))
 -                      die("multiple stage entries for merged file '%s'",
 -                              ce->name);
 -              if (ce_stage(ce) > ce_stage(next_ce))
 -                      die("unordered stage entries for '%s'",
 -                              ce->name);
 +      unsigned int i;
 +
 +      for (i = 1; i < istate->cache_nr; i++) {
 +              struct cache_entry *ce = istate->cache[i - 1];
 +              struct cache_entry *next_ce = istate->cache[i];
 +              int name_compare = strcmp(ce->name, next_ce->name);
 +
 +              if (0 < name_compare)
 +                      die("unordered stage entries in index");
 +              if (!name_compare) {
 +                      if (!ce_stage(ce))
 +                              die("multiple stage entries for merged file '%s'",
 +                                  ce->name);
 +                      if (ce_stage(ce) > ce_stage(next_ce))
 +                              die("unordered stage entries for '%s'",
 +                                  ce->name);
 +              }
        }
  }
  
@@@ -1569,6 -1564,9 +1571,6 @@@ int do_read_index(struct index_state *i
                ce = create_from_disk(disk_ce, &consumed, previous_name);
                set_index_entry(istate, i, ce);
  
 -              if (i > 0)
 -                      check_ce_order(istate->cache[i - 1], ce);
 -
                src_offset += consumed;
        }
        strbuf_release(&previous_name_buf);
@@@ -1612,10 -1610,11 +1614,10 @@@ int read_index_from(struct index_state 
  
        ret = do_read_index(istate, path, 0);
        split_index = istate->split_index;
 -      if (!split_index)
 -              return ret;
 -
 -      if (is_null_sha1(split_index->base_sha1))
 +      if (!split_index || is_null_sha1(split_index->base_sha1)) {
 +              check_ce_order(istate);
                return ret;
 +      }
  
        if (split_index->base)
                discard_index(split_index->base);
                                     sha1_to_hex(split_index->base_sha1)),
                    sha1_to_hex(split_index->base->sha1));
        merge_base_index(istate);
 +      check_ce_order(istate);
        return ret;
  }