Skip to content

Commit 7615cf9

Browse files
avargitster
authored andcommitted
various: add missing clear_pathspec(), fix leaks
Fix memory leaks resulting from a missing clear_pathspec(). - archive.c: Plug a leak in the "struct archiver_args", and clear_pathspec() the "pathspec" member that the "parse_pathspec_arg()" call in this function populates. - builtin/clean.c: Fix a memory leak that's been with us since 893d839 (clean: convert to use parse_pathspec, 2013-07-14). - builtin/reset.c: Add clear_pathspec() calls to cmd_reset(), including to the codepaths where we'd return early. - builtin/stash.c: Call clear_pathspec() on the pathspec initialized in push_stash(). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 81e5c39 commit 7615cf9

10 files changed

+24
-5
lines changed

archive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
710710

711711
string_list_clear_func(&args.extra_files, extra_file_info_clear);
712712
free(args.refname);
713+
clear_pathspec(&args.pathspec);
713714

714715
return rc;
715716
}

builtin/clean.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,5 +1092,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10921092
strbuf_release(&buf);
10931093
string_list_clear(&del_list, 0);
10941094
string_list_clear(&exclude_list, 0);
1095+
clear_pathspec(&pathspec);
10951096
return (errors != 0);
10961097
}

builtin/reset.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
390390
if (reset_type != NONE)
391391
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
392392
trace2_cmd_mode("patch-interactive");
393-
return run_add_interactive(rev, "--patch=reset", &pathspec);
393+
update_ref_status = run_add_interactive(rev, "--patch=reset", &pathspec);
394+
goto cleanup;
394395
}
395396

396397
/* git reset tree [--] paths... can be used to
@@ -439,8 +440,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
439440
LOCK_DIE_ON_ERROR);
440441
if (reset_type == MIXED) {
441442
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
442-
if (read_from_tree(&pathspec, &oid, intent_to_add))
443-
return 1;
443+
if (read_from_tree(&pathspec, &oid, intent_to_add)) {
444+
update_ref_status = 1;
445+
goto cleanup;
446+
}
444447
the_index.updated_skipworktree = 1;
445448
if (!no_refresh && get_git_work_tree()) {
446449
uint64_t t_begin, t_delta_in_ms;
@@ -488,5 +491,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
488491

489492
discard_index(&the_index);
490493

494+
cleanup:
495+
clear_pathspec(&pathspec);
491496
return update_ref_status;
492497
}

builtin/stash.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
17271727
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
17281728
OPT_END()
17291729
};
1730+
int ret;
17301731

17311732
if (argc) {
17321733
force_assume = !strcmp(argv[0], "-p");
@@ -1766,8 +1767,10 @@ static int push_stash(int argc, const char **argv, const char *prefix,
17661767
die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
17671768
}
17681769

1769-
return do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
1770-
include_untracked, only_staged);
1770+
ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
1771+
include_untracked, only_staged);
1772+
clear_pathspec(&ps);
1773+
return ret;
17711774
}
17721775

17731776
static int push_stash_unassumed(int argc, const char **argv, const char *prefix)

t/t5001-archive-attr.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
test_description='git archive attribute tests'
44

55
TEST_CREATE_REPO_NO_TEMPLATE=1
6+
TEST_PASSES_SANITIZE_LEAK=true
67
. ./test-lib.sh
78

89
SUBSTFORMAT='%H (%h)%n'

t/t5004-archive-corner-cases.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='test corner cases of git-archive'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
# the 10knuls.tar file is used to test for an empty git generated tar

t/t7105-reset-patch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='git reset --patch'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./lib-patch-mode.sh
57

68
test_expect_success PERL 'setup' '

t/t7106-reset-unborn-branch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='git reset should work on unborn branch'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'setup' '

t/t7107-reset-pathspec-file.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='reset --pathspec-from-file'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_tick

t/t7301-clean-interactive.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git clean -i basic tests'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67
. "$TEST_DIRECTORY"/lib-terminal.sh
78

0 commit comments

Comments
 (0)