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
This commit is contained in:
Junio C Hamano 2023-06-23 11:21:17 -07:00
commit 4e4fc50cf7
16 changed files with 29 additions and 7 deletions

View file

@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
if (!remote_find_tracking(remote, &tracking->spec)) { if (!remote_find_tracking(remote, &tracking->spec)) {
switch (++tracking->matches) { switch (++tracking->matches) {
case 1: case 1:
string_list_append(tracking->srcs, tracking->spec.src); string_list_append_nodup(tracking->srcs, tracking->spec.src);
tracking->remote = remote->name; tracking->remote = remote->name;
break; break;
case 2: case 2:
@ -233,7 +233,7 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
return -1; return -1;
} }
tracking->remote = xstrdup(branch->remote_name); tracking->remote = branch->remote_name;
for (i = 0; i < branch->merge_nr; i++) for (i = 0; i < branch->merge_nr; i++)
string_list_append(tracking->srcs, branch->merge_name[i]); string_list_append(tracking->srcs, branch->merge_name[i]);
return 0; 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, if (!skip_prefix(tracking.srcs->items[0].string,
"refs/heads/", &tracked_branch) || "refs/heads/", &tracked_branch) ||
strcmp(tracked_branch, new_ref)) strcmp(tracked_branch, new_ref))
return; goto cleanup;
} }
if (tracking.srcs->nr < 1) 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; char *tracking_branch = cb_data;
struct refspec_item query; struct refspec_item query;
int res;
memset(&query, 0, sizeof(struct refspec_item)); memset(&query, 0, sizeof(struct refspec_item));
query.dst = tracking_branch; 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) 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, const char *orig_ref, enum branch_track track,
int quiet) int quiet)
{ {
char *real_orig_ref; char *real_orig_ref = NULL;
dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL); dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
setup_tracking(new_ref, real_orig_ref, track, quiet); setup_tracking(new_ref, real_orig_ref, track, quiet);
free(real_orig_ref);
} }
/** /**

View file

@ -832,6 +832,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (list) if (list)
setup_auto_pager("branch", 1); setup_auto_pager("branch", 1);
UNLEAK(sorting_options);
if (delete) { if (delete) {
if (!argc) if (!argc)
die(_("branch name required")); die(_("branch name required"));

View file

@ -156,9 +156,12 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
*/ */
break; break;
case 1: /* happy */ case 1: /* happy */
if (abbrev_ref) if (abbrev_ref) {
char *old = full;
full = shorten_unambiguous_ref(full, full = shorten_unambiguous_ref(full,
abbrev_ref_strict); abbrev_ref_strict);
free(old);
}
show_with_type(type, full); show_with_type(type, full);
break; break;
default: /* ambiguous */ default: /* ambiguous */

View file

@ -3841,6 +3841,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
output[0] = '\t'; output[0] = '\t';
} }
} else { } else {
strbuf_release(&copystr);
copystr = store_create_section(new_name, &store); copystr = store_create_section(new_name, &store);
} }
} }
@ -3887,6 +3888,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
free(filename_buf); free(filename_buf);
config_store_data_clear(&store); config_store_data_clear(&store);
strbuf_release(&buf); strbuf_release(&buf);
strbuf_release(&copystr);
return ret; return ret;
} }

View file

@ -890,7 +890,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
{ {
int i, matched_negative = 0; int i, matched_negative = 0;
int find_src = !query->src; 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; const char *needle = find_src ? query->dst : query->src;
/* /*

View file

@ -5,6 +5,7 @@ test_description='test <branch>@{upstream} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh

View file

@ -4,6 +4,7 @@ test_description='test various @{X} syntax combinations together'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
check() { check() {

View file

@ -4,6 +4,7 @@ test_description='test <branch>@{push} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
resolve () { resolve () {

View file

@ -5,6 +5,7 @@ test_description='tests for git branch --track'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
test_expect_success 'setup' ' test_expect_success 'setup' '

View file

@ -8,6 +8,7 @@ test_description='git branch assorted tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh . "$TEST_DIRECTORY"/lib-rebase.sh

View file

@ -9,6 +9,7 @@ This script aims to check the behavior of those corner cases.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
expect_branch() { expect_branch() {

View file

@ -5,6 +5,7 @@ test_description='tracking branch update checks for git push'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
test_expect_success 'setup' ' test_expect_success 'setup' '

View file

@ -5,6 +5,7 @@ test_description='pushing to a mirror repository'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
D=$(pwd) D=$(pwd)

View file

@ -2,6 +2,7 @@
test_description='tagopt variable affects "git fetch" and is overridden by commandline.' test_description='tagopt variable affects "git fetch" and is overridden by commandline.'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
setup_clone () { setup_clone () {

View file

@ -5,6 +5,7 @@ test_description='remote tracking stats'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
advance () { advance () {

View file

@ -5,6 +5,7 @@
test_description='git status' test_description='git status'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh . "$TEST_DIRECTORY"/lib-terminal.sh