summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-06-23 18:21:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-06-23 18:21:17 (GMT)
commit4e4fc50cf733bb0071e43ea128b13439b93975d2 (patch)
treea9b89a59e36a3a0687ec1d3eb21a30cc909070c9
parent1d15be363ccf0ff4337886568087d0467c93c9a9 (diff)
parent80d32e84b5ffc0f678fef2560ef386b1ef98b964 (diff)
downloadgit-4e4fc50cf733bb0071e43ea128b13439b93975d2.zip
git-4e4fc50cf733bb0071e43ea128b13439b93975d2.tar.gz
git-4e4fc50cf733bb0071e43ea128b13439b93975d2.tar.bz2
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
-rw-r--r--branch.c14
-rw-r--r--builtin/branch.c2
-rw-r--r--builtin/rev-parse.c5
-rw-r--r--config.c2
-rw-r--r--remote.c2
-rwxr-xr-xt/t1507-rev-parse-upstream.sh1
-rwxr-xr-xt/t1508-at-combinations.sh1
-rwxr-xr-xt/t1514-rev-parse-push.sh1
-rwxr-xr-xt/t2027-checkout-track.sh1
-rwxr-xr-xt/t3200-branch.sh1
-rwxr-xr-xt/t3204-branch-name-interpretation.sh1
-rwxr-xr-xt/t5404-tracking-branches.sh1
-rwxr-xr-xt/t5517-push-mirror.sh1
-rwxr-xr-xt/t5525-fetch-tagopt.sh1
-rwxr-xr-xt/t6040-tracking-info.sh1
-rwxr-xr-xt/t7508-status.sh1
16 files changed, 29 insertions, 7 deletions
diff --git a/branch.c b/branch.c
index ba3914a..d88f50a 100644
--- a/branch.c
+++ b/branch.c
@@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
if (!remote_find_tracking(remote, &tracking->spec)) {
switch (++tracking->matches) {
case 1:
- string_list_append(tracking->srcs, tracking->spec.src);
+ string_list_append_nodup(tracking->srcs, tracking->spec.src);
tracking->remote = remote->name;
break;
case 2:
@@ -233,7 +233,7 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
return -1;
}
- tracking->remote = xstrdup(branch->remote_name);
+ tracking->remote = branch->remote_name;
for (i = 0; i < branch->merge_nr; i++)
string_list_append(tracking->srcs, branch->merge_name[i]);
return 0;
@@ -333,7 +333,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
if (!skip_prefix(tracking.srcs->items[0].string,
"refs/heads/", &tracked_branch) ||
strcmp(tracked_branch, new_ref))
- return;
+ goto cleanup;
}
if (tracking.srcs->nr < 1)
@@ -480,9 +480,12 @@ static int check_tracking_branch(struct remote *remote, void *cb_data)
{
char *tracking_branch = cb_data;
struct refspec_item query;
+ int res;
memset(&query, 0, sizeof(struct refspec_item));
query.dst = tracking_branch;
- return !remote_find_tracking(remote, &query);
+ res = !remote_find_tracking(remote, &query);
+ free(query.src);
+ return res;
}
static int validate_remote_tracking_branch(char *ref)
@@ -638,9 +641,10 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
const char *orig_ref, enum branch_track track,
int quiet)
{
- char *real_orig_ref;
+ char *real_orig_ref = NULL;
dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
setup_tracking(new_ref, real_orig_ref, track, quiet);
+ free(real_orig_ref);
}
/**
diff --git a/builtin/branch.c b/builtin/branch.c
index e6c2655..075e580 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -832,6 +832,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (list)
setup_auto_pager("branch", 1);
+ UNLEAK(sorting_options);
+
if (delete) {
if (!argc)
die(_("branch name required"));
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 852e49e..d2eb239 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -156,9 +156,12 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
*/
break;
case 1: /* happy */
- if (abbrev_ref)
+ if (abbrev_ref) {
+ char *old = full;
full = shorten_unambiguous_ref(full,
abbrev_ref_strict);
+ free(old);
+ }
show_with_type(type, full);
break;
default: /* ambiguous */
diff --git a/config.c b/config.c
index 5a4bb3f..2eeb662 100644
--- a/config.c
+++ b/config.c
@@ -3841,6 +3841,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
output[0] = '\t';
}
} else {
+ strbuf_release(&copystr);
copystr = store_create_section(new_name, &store);
}
}
@@ -3887,6 +3888,7 @@ out_no_rollback:
free(filename_buf);
config_store_data_clear(&store);
strbuf_release(&buf);
+ strbuf_release(&copystr);
return ret;
}
diff --git a/remote.c b/remote.c
index 0764fca..1bcd36e 100644
--- a/remote.c
+++ b/remote.c
@@ -890,7 +890,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
{
int i, matched_negative = 0;
int find_src = !query->src;
- struct string_list reversed = STRING_LIST_INIT_NODUP;
+ struct string_list reversed = STRING_LIST_INIT_DUP;
const char *needle = find_src ? query->dst : query->src;
/*
diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh
index cb9ef7e..b9af6b3 100755
--- a/t/t1507-rev-parse-upstream.sh
+++ b/t/t1507-rev-parse-upstream.sh
@@ -5,6 +5,7 @@ test_description='test <branch>@{upstream} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 87a4286..e841309 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -4,6 +4,7 @@ test_description='test various @{X} syntax combinations together'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
check() {
diff --git a/t/t1514-rev-parse-push.sh b/t/t1514-rev-parse-push.sh
index d868a08..a835a19 100755
--- a/t/t1514-rev-parse-push.sh
+++ b/t/t1514-rev-parse-push.sh
@@ -4,6 +4,7 @@ test_description='test <branch>@{push} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
resolve () {
diff --git a/t/t2027-checkout-track.sh b/t/t2027-checkout-track.sh
index dca35aa..a8bbc60 100755
--- a/t/t2027-checkout-track.sh
+++ b/t/t2027-checkout-track.sh
@@ -5,6 +5,7 @@ test_description='tests for git branch --track'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 98b6c8a..daf1666 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -8,6 +8,7 @@ test_description='git branch assorted tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
diff --git a/t/t3204-branch-name-interpretation.sh b/t/t3204-branch-name-interpretation.sh
index 3399344..594e3e4 100755
--- a/t/t3204-branch-name-interpretation.sh
+++ b/t/t3204-branch-name-interpretation.sh
@@ -9,6 +9,7 @@ This script aims to check the behavior of those corner cases.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
expect_branch() {
diff --git a/t/t5404-tracking-branches.sh b/t/t5404-tracking-branches.sh
index cc07889..51737ee 100755
--- a/t/t5404-tracking-branches.sh
+++ b/t/t5404-tracking-branches.sh
@@ -5,6 +5,7 @@ test_description='tracking branch update checks for git push'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t5517-push-mirror.sh b/t/t5517-push-mirror.sh
index a448e16..6d4944a 100755
--- a/t/t5517-push-mirror.sh
+++ b/t/t5517-push-mirror.sh
@@ -5,6 +5,7 @@ test_description='pushing to a mirror repository'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
D=$(pwd)
diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh
index 45815f7..3a28f1d 100755
--- a/t/t5525-fetch-tagopt.sh
+++ b/t/t5525-fetch-tagopt.sh
@@ -2,6 +2,7 @@
test_description='tagopt variable affects "git fetch" and is overridden by commandline.'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
setup_clone () {
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index a313849..7ddbd96 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -5,6 +5,7 @@ test_description='remote tracking stats'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
advance () {
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index a3050ad..3656770 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -5,6 +5,7 @@
test_description='git status'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh