Skip to content

Commit 199074f

Browse files
committed
Merge branch 'rj/restore-plug-leaks'
Leaks from "git restore" have been plugged. * rj/restore-plug-leaks: checkout: plug some leaks in git-restore
2 parents 11c821f + 2f64da0 commit 199074f

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

builtin/checkout.c

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,10 +1702,11 @@ static char cb_option = 'b';
17021702

17031703
static int checkout_main(int argc, const char **argv, const char *prefix,
17041704
struct checkout_opts *opts, struct option *options,
1705-
const char * const usagestr[],
1706-
struct branch_info *new_branch_info)
1705+
const char * const usagestr[])
17071706
{
17081707
int parseopt_flags = 0;
1708+
struct branch_info new_branch_info = { 0 };
1709+
int ret;
17091710

17101711
opts->overwrite_ignore = 1;
17111712
opts->prefix = prefix;
@@ -1821,7 +1822,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
18211822
opts->track == BRANCH_TRACK_UNSPECIFIED &&
18221823
!opts->new_branch;
18231824
int n = parse_branchname_arg(argc, argv, dwim_ok,
1824-
new_branch_info, opts, &rev);
1825+
&new_branch_info, opts, &rev);
18251826
argv += n;
18261827
argc -= n;
18271828
} else if (!opts->accept_ref && opts->from_treeish) {
@@ -1830,7 +1831,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
18301831
if (repo_get_oid_mb(the_repository, opts->from_treeish, &rev))
18311832
die(_("could not resolve %s"), opts->from_treeish);
18321833

1833-
setup_new_branch_info_and_source_tree(new_branch_info,
1834+
setup_new_branch_info_and_source_tree(&new_branch_info,
18341835
opts, &rev,
18351836
opts->from_treeish);
18361837

@@ -1850,7 +1851,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
18501851
* Try to give more helpful suggestion.
18511852
* new_branch && argc > 1 will be caught later.
18521853
*/
1853-
if (opts->new_branch && argc == 1 && !new_branch_info->commit)
1854+
if (opts->new_branch && argc == 1 && !new_branch_info.commit)
18541855
die(_("'%s' is not a commit and a branch '%s' cannot be created from it"),
18551856
argv[0], opts->new_branch);
18561857

@@ -1900,9 +1901,16 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
19001901
}
19011902

19021903
if (opts->patch_mode || opts->pathspec.nr)
1903-
return checkout_paths(opts, new_branch_info);
1904+
ret = checkout_paths(opts, &new_branch_info);
19041905
else
1905-
return checkout_branch(opts, new_branch_info);
1906+
ret = checkout_branch(opts, &new_branch_info);
1907+
1908+
branch_info_release(&new_branch_info);
1909+
clear_pathspec(&opts->pathspec);
1910+
free(opts->pathspec_from_file);
1911+
free(options);
1912+
1913+
return ret;
19061914
}
19071915

19081916
int cmd_checkout(int argc, const char **argv, const char *prefix)
@@ -1920,8 +1928,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
19201928
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode (default)")),
19211929
OPT_END()
19221930
};
1923-
int ret;
1924-
struct branch_info new_branch_info = { 0 };
19251931

19261932
memset(&opts, 0, sizeof(opts));
19271933
opts.dwim_new_local_branch = 1;
@@ -1951,13 +1957,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
19511957
options = add_common_switch_branch_options(&opts, options);
19521958
options = add_checkout_path_options(&opts, options);
19531959

1954-
ret = checkout_main(argc, argv, prefix, &opts,
1955-
options, checkout_usage, &new_branch_info);
1956-
branch_info_release(&new_branch_info);
1957-
clear_pathspec(&opts.pathspec);
1958-
free(opts.pathspec_from_file);
1959-
FREE_AND_NULL(options);
1960-
return ret;
1960+
return checkout_main(argc, argv, prefix, &opts, options,
1961+
checkout_usage);
19611962
}
19621963

19631964
int cmd_switch(int argc, const char **argv, const char *prefix)
@@ -1975,8 +1976,6 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
19751976
N_("throw away local modifications")),
19761977
OPT_END()
19771978
};
1978-
int ret;
1979-
struct branch_info new_branch_info = { 0 };
19801979

19811980
memset(&opts, 0, sizeof(opts));
19821981
opts.dwim_new_local_branch = 1;
@@ -1995,11 +1994,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
19951994

19961995
cb_option = 'c';
19971996

1998-
ret = checkout_main(argc, argv, prefix, &opts,
1999-
options, switch_branch_usage, &new_branch_info);
2000-
branch_info_release(&new_branch_info);
2001-
FREE_AND_NULL(options);
2002-
return ret;
1997+
return checkout_main(argc, argv, prefix, &opts, options,
1998+
switch_branch_usage);
20031999
}
20042000

20052001
int cmd_restore(int argc, const char **argv, const char *prefix)
@@ -2018,8 +2014,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
20182014
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")),
20192015
OPT_END()
20202016
};
2021-
int ret;
2022-
struct branch_info new_branch_info = { 0 };
20232017

20242018
memset(&opts, 0, sizeof(opts));
20252019
opts.accept_ref = 0;
@@ -2034,9 +2028,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
20342028
options = add_common_options(&opts, options);
20352029
options = add_checkout_path_options(&opts, options);
20362030

2037-
ret = checkout_main(argc, argv, prefix, &opts,
2038-
options, restore_usage, &new_branch_info);
2039-
branch_info_release(&new_branch_info);
2040-
FREE_AND_NULL(options);
2041-
return ret;
2031+
return checkout_main(argc, argv, prefix, &opts, options,
2032+
restore_usage);
20422033
}

t/t2070-restore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='restore basic functionality'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
test_expect_success 'setup' '

t/t2071-restore-patch.sh

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

33
test_description='git restore --patch'
44

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

78
test_expect_success 'setup' '

t/t2072-restore-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='restore --pathspec-from-file'
44

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

78
test_tick

t/t6418-merge-text-auto.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test_description='CRLF merge conflict across text=auto change
1515
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1616
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1717

18+
TEST_PASSES_SANITIZE_LEAK=true
1819
. ./test-lib.sh
1920

2021
test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b

0 commit comments

Comments
 (0)