Merge branch 'js/commit-graph-parse-leakfix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 07:45:28 +0000 (16:45 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 07:45:28 +0000 (16:45 +0900)
Leakfix.

* js/commit-graph-parse-leakfix:
commit-graph: fix memory leak

1  2 
commit-graph.c
diff --combined commit-graph.c
index 7bcc9bb7e0f9965a2ab3176c0416943430c6a6aa,4bce70d35c9baaa5504c7a15d8208d7ffc185df8..7c5e54875fdacdf77235a077c9928f7d3bf0d001
@@@ -267,8 -267,10 +267,10 @@@ struct commit_graph *parse_commit_graph
                last_chunk_offset = chunk_offset;
        }
  
-       if (verify_commit_graph_lite(graph))
+       if (verify_commit_graph_lite(graph)) {
+               free(graph);
                return NULL;
+       }
  
        return graph;
  }
@@@ -397,11 -399,6 +399,11 @@@ static void fill_commit_graph_info(stru
        item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
  }
  
 +static inline void set_commit_tree(struct commit *c, struct tree *t)
 +{
 +      c->maybe_tree = t;
 +}
 +
  static int fill_commit_in_graph(struct repository *r,
                                struct commit *item,
                                struct commit_graph *g, uint32_t pos)
        item->object.parsed = 1;
        item->graph_pos = pos;
  
 -      item->maybe_tree = NULL;
 +      set_commit_tree(item, NULL);
  
        date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
        date_low = get_be32(commit_data + g->hash_len + 12);
@@@ -501,7 -498,7 +503,7 @@@ static struct tree *load_tree_for_commi
                                           GRAPH_DATA_WIDTH * (c->graph_pos);
  
        hashcpy(oid.hash, commit_data);
 -      c->maybe_tree = lookup_tree(r, &oid);
 +      set_commit_tree(c, lookup_tree(r, &oid));
  
        return c->maybe_tree;
  }