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
893d839970
(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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
81e5c39cf6
commit
7615cf94d2
@ -710,6 +710,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
|
|||||||
|
|
||||||
string_list_clear_func(&args.extra_files, extra_file_info_clear);
|
string_list_clear_func(&args.extra_files, extra_file_info_clear);
|
||||||
free(args.refname);
|
free(args.refname);
|
||||||
|
clear_pathspec(&args.pathspec);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -1092,5 +1092,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
|
|||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
string_list_clear(&del_list, 0);
|
string_list_clear(&del_list, 0);
|
||||||
string_list_clear(&exclude_list, 0);
|
string_list_clear(&exclude_list, 0);
|
||||||
|
clear_pathspec(&pathspec);
|
||||||
return (errors != 0);
|
return (errors != 0);
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||||||
if (reset_type != NONE)
|
if (reset_type != NONE)
|
||||||
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
|
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
|
||||||
trace2_cmd_mode("patch-interactive");
|
trace2_cmd_mode("patch-interactive");
|
||||||
return run_add_interactive(rev, "--patch=reset", &pathspec);
|
update_ref_status = run_add_interactive(rev, "--patch=reset", &pathspec);
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* git reset tree [--] paths... can be used to
|
/* git reset tree [--] paths... can be used to
|
||||||
@ -439,8 +440,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||||||
LOCK_DIE_ON_ERROR);
|
LOCK_DIE_ON_ERROR);
|
||||||
if (reset_type == MIXED) {
|
if (reset_type == MIXED) {
|
||||||
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
|
int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
|
||||||
if (read_from_tree(&pathspec, &oid, intent_to_add))
|
if (read_from_tree(&pathspec, &oid, intent_to_add)) {
|
||||||
return 1;
|
update_ref_status = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
the_index.updated_skipworktree = 1;
|
the_index.updated_skipworktree = 1;
|
||||||
if (!no_refresh && get_git_work_tree()) {
|
if (!no_refresh && get_git_work_tree()) {
|
||||||
uint64_t t_begin, t_delta_in_ms;
|
uint64_t t_begin, t_delta_in_ms;
|
||||||
@ -488,5 +491,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
discard_index(&the_index);
|
discard_index(&the_index);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
clear_pathspec(&pathspec);
|
||||||
return update_ref_status;
|
return update_ref_status;
|
||||||
}
|
}
|
||||||
|
@ -1727,6 +1727,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
|
|||||||
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
|
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (argc) {
|
if (argc) {
|
||||||
force_assume = !strcmp(argv[0], "-p");
|
force_assume = !strcmp(argv[0], "-p");
|
||||||
@ -1766,8 +1767,10 @@ static int push_stash(int argc, const char **argv, const char *prefix,
|
|||||||
die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
|
die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
|
||||||
}
|
}
|
||||||
|
|
||||||
return do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
|
ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
|
||||||
include_untracked, only_staged);
|
include_untracked, only_staged);
|
||||||
|
clear_pathspec(&ps);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int push_stash_unassumed(int argc, const char **argv, const char *prefix)
|
static int push_stash_unassumed(int argc, const char **argv, const char *prefix)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
test_description='git archive attribute tests'
|
test_description='git archive attribute tests'
|
||||||
|
|
||||||
TEST_CREATE_REPO_NO_TEMPLATE=1
|
TEST_CREATE_REPO_NO_TEMPLATE=1
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
SUBSTFORMAT='%H (%h)%n'
|
SUBSTFORMAT='%H (%h)%n'
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
test_description='test corner cases of git-archive'
|
test_description='test corner cases of git-archive'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
# the 10knuls.tar file is used to test for an empty git generated tar
|
# the 10knuls.tar file is used to test for an empty git generated tar
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
test_description='git reset --patch'
|
test_description='git reset --patch'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./lib-patch-mode.sh
|
. ./lib-patch-mode.sh
|
||||||
|
|
||||||
test_expect_success PERL 'setup' '
|
test_expect_success PERL 'setup' '
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
test_description='git reset should work on unborn branch'
|
test_description='git reset should work on unborn branch'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
test_expect_success 'setup' '
|
test_expect_success 'setup' '
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
test_description='reset --pathspec-from-file'
|
test_description='reset --pathspec-from-file'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
test_tick
|
test_tick
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
test_description='git clean -i basic tests'
|
test_description='git clean -i basic tests'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
. "$TEST_DIRECTORY"/lib-terminal.sh
|
. "$TEST_DIRECTORY"/lib-terminal.sh
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user