diff options
author | Jeff King <peff@peff.net> | 2017-09-05 09:04:51 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-06 18:06:26 +0900 |
commit | afbb8838b7d4d1887da1e1871f8e9ccd01ae1138 (patch) | |
tree | e6a3f3db9bcc1b2508b9484a8d32c8684cc29374 /builtin/reset.c | |
parent | reset: make tree counting less confusing (diff) | |
download | tgif-afbb8838b7d4d1887da1e1871f8e9ccd01ae1138.tar.xz |
reset: free allocated tree buffers
We read the tree objects with fill_tree_descriptor(), but
never actually free the resulting buffers, causing a memory
leak. This isn't a huge deal because we call this code at
most twice per program invocation. But it does potentially
double our heap usage if you have large root trees. Let's
free the trees before returning.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/reset.c')
-rw-r--r-- | builtin/reset.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/builtin/reset.c b/builtin/reset.c index 70230056a8..0295c961a3 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -44,10 +44,11 @@ static inline int is_merge(void) static int reset_index(const struct object_id *oid, int reset_type, int quiet) { - int nr = 0; + int i, nr = 0; struct tree_desc desc[2]; struct tree *tree; struct unpack_trees_options opts; + int ret = -1; memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; @@ -81,19 +82,26 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet) opts.fn = twoway_merge; } - if (!fill_tree_descriptor(desc + nr, oid)) - return error(_("Failed to find tree of %s."), oid_to_hex(oid)); + if (!fill_tree_descriptor(desc + nr, oid)) { + error(_("Failed to find tree of %s."), oid_to_hex(oid)); + goto out; + } nr++; if (unpack_trees(nr, desc, &opts)) - return -1; + goto out; if (reset_type == MIXED || reset_type == HARD) { tree = parse_tree_indirect(oid); prime_cache_tree(&the_index, tree); } - return 0; + ret = 0; + +out: + for (i = 0; i < nr; i++) + free((void *)desc[i].buffer); + return ret; } static void print_new_head_line(struct commit *commit) |