Skip to content

Commit

Permalink
checkout, read-tree: fix leak of unpack_trees_options.dir
Browse files Browse the repository at this point in the history
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
newren authored and gitster committed Sep 27, 2021
1 parent 446cc55 commit c512d27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
init_tree_desc(&trees[1], tree->buffer, tree->size);

ret = unpack_trees(2, trees, &topts);
if (topts.dir) {
dir_clear(topts.dir);
FREE_AND_NULL(topts.dir);
}
clear_unpack_trees_porcelain(&topts);
if (ret == -1) {
/*
Expand Down
5 changes: 5 additions & 0 deletions builtin/read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
if (unpack_trees(nr_trees, t, &opts))
return 128;

if (opts.dir) {
dir_clear(opts.dir);
FREE_AND_NULL(opts.dir);
}

if (opts.debug_unpack || opts.dry_run)
return 0; /* do not write the index out */

Expand Down

0 comments on commit c512d27

Please sign in to comment.