Skip to content

Commit 4e4fc50

Browse files
committed
Merge branch 'rj/leakfixes'
Leakfixes * rj/leakfixes: tests: mark as passing with SANITIZE=leak config: fix a leak in git_config_copy_or_rename_section_in_file branch: fix a leak in cmd_branch branch: fix a leak in setup_tracking rev-parse: fix a leak with --abbrev-ref branch: fix a leak in setup_tracking branch: fix a leak in check_tracking_branch branch: fix a leak in inherit_tracking branch: fix a leak in dwim_and_setup_tracking remote: fix a leak in query_matches_negative_refspec config: fix a leak in git_config_copy_or_rename_section_in_file
2 parents 1d15be3 + 80d32e8 commit 4e4fc50

16 files changed

+29
-7
lines changed

branch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
3737
if (!remote_find_tracking(remote, &tracking->spec)) {
3838
switch (++tracking->matches) {
3939
case 1:
40-
string_list_append(tracking->srcs, tracking->spec.src);
40+
string_list_append_nodup(tracking->srcs, tracking->spec.src);
4141
tracking->remote = remote->name;
4242
break;
4343
case 2:
@@ -233,7 +233,7 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
233233
return -1;
234234
}
235235

236-
tracking->remote = xstrdup(branch->remote_name);
236+
tracking->remote = branch->remote_name;
237237
for (i = 0; i < branch->merge_nr; i++)
238238
string_list_append(tracking->srcs, branch->merge_name[i]);
239239
return 0;
@@ -333,7 +333,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
333333
if (!skip_prefix(tracking.srcs->items[0].string,
334334
"refs/heads/", &tracked_branch) ||
335335
strcmp(tracked_branch, new_ref))
336-
return;
336+
goto cleanup;
337337
}
338338

339339
if (tracking.srcs->nr < 1)
@@ -480,9 +480,12 @@ static int check_tracking_branch(struct remote *remote, void *cb_data)
480480
{
481481
char *tracking_branch = cb_data;
482482
struct refspec_item query;
483+
int res;
483484
memset(&query, 0, sizeof(struct refspec_item));
484485
query.dst = tracking_branch;
485-
return !remote_find_tracking(remote, &query);
486+
res = !remote_find_tracking(remote, &query);
487+
free(query.src);
488+
return res;
486489
}
487490

488491
static int validate_remote_tracking_branch(char *ref)
@@ -638,9 +641,10 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
638641
const char *orig_ref, enum branch_track track,
639642
int quiet)
640643
{
641-
char *real_orig_ref;
644+
char *real_orig_ref = NULL;
642645
dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
643646
setup_tracking(new_ref, real_orig_ref, track, quiet);
647+
free(real_orig_ref);
644648
}
645649

646650
/**

builtin/branch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
832832
if (list)
833833
setup_auto_pager("branch", 1);
834834

835+
UNLEAK(sorting_options);
836+
835837
if (delete) {
836838
if (!argc)
837839
die(_("branch name required"));

builtin/rev-parse.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
156156
*/
157157
break;
158158
case 1: /* happy */
159-
if (abbrev_ref)
159+
if (abbrev_ref) {
160+
char *old = full;
160161
full = shorten_unambiguous_ref(full,
161162
abbrev_ref_strict);
163+
free(old);
164+
}
162165
show_with_type(type, full);
163166
break;
164167
default: /* ambiguous */

config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,6 +3841,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
38413841
output[0] = '\t';
38423842
}
38433843
} else {
3844+
strbuf_release(&copystr);
38443845
copystr = store_create_section(new_name, &store);
38453846
}
38463847
}
@@ -3887,6 +3888,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
38873888
free(filename_buf);
38883889
config_store_data_clear(&store);
38893890
strbuf_release(&buf);
3891+
strbuf_release(&copystr);
38903892
return ret;
38913893
}
38923894

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
890890
{
891891
int i, matched_negative = 0;
892892
int find_src = !query->src;
893-
struct string_list reversed = STRING_LIST_INIT_NODUP;
893+
struct string_list reversed = STRING_LIST_INIT_DUP;
894894
const char *needle = find_src ? query->dst : query->src;
895895

896896
/*

t/t1507-rev-parse-upstream.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='test <branch>@{upstream} syntax'
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

t/t1508-at-combinations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test various @{X} syntax combinations together'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
check() {

t/t1514-rev-parse-push.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test <branch>@{push} syntax'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
resolve () {

t/t2027-checkout-track.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='tests for git branch --track'
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/t3200-branch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_description='git branch assorted tests'
88
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

11+
TEST_PASSES_SANITIZE_LEAK=true
1112
. ./test-lib.sh
1213
. "$TEST_DIRECTORY"/lib-rebase.sh
1314

0 commit comments

Comments
 (0)