Skip to content

Commit 11ee9a7

Browse files
pks-tgitster
authored andcommitted
bundle: plug leaks in create_bundle()
When creating a bundle, we set up a revision walk, but never release data associated with it. Furthermore, we create a mostly-shallow copy of that revision walk where we only adapt its pending objects such that we can reuse the walk. While that copy must not be released, the pending objects array need to be. Plug those memory leaks by releasing the revision walk and the pending objects of the copied revision walk. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb8c43d commit 11ee9a7

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

bundle.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ int create_bundle(struct repository *r, const char *path,
500500
struct rev_info revs, revs_copy;
501501
int min_version = 2;
502502
struct bundle_prerequisites_info bpi;
503+
int ret;
503504
int i;
504505

505506
/* init revs to list objects for pack-objects later */
@@ -525,8 +526,8 @@ int create_bundle(struct repository *r, const char *path,
525526
min_version = 3;
526527

527528
if (argc > 1) {
528-
error(_("unrecognized argument: %s"), argv[1]);
529-
goto err;
529+
ret = error(_("unrecognized argument: %s"), argv[1]);
530+
goto out;
530531
}
531532

532533
bundle_to_stdout = !strcmp(path, "-");
@@ -591,23 +592,31 @@ int create_bundle(struct repository *r, const char *path,
591592

592593
/* write bundle refs */
593594
ref_count = write_bundle_refs(bundle_fd, &revs_copy);
594-
if (!ref_count)
595+
if (!ref_count) {
595596
die(_("Refusing to create empty bundle."));
596-
else if (ref_count < 0)
597-
goto err;
597+
} else if (ref_count < 0) {
598+
ret = -1;
599+
goto out;
600+
}
598601

599602
/* write pack */
600-
if (write_pack_data(bundle_fd, &revs_copy, pack_options))
601-
goto err;
603+
if (write_pack_data(bundle_fd, &revs_copy, pack_options)) {
604+
ret = -1;
605+
goto out;
606+
}
602607

603608
if (!bundle_to_stdout) {
604609
if (commit_lock_file(&lock))
605610
die_errno(_("cannot create '%s'"), path);
606611
}
607-
return 0;
608-
err:
612+
613+
ret = 0;
614+
615+
out:
616+
object_array_clear(&revs_copy.pending);
617+
release_revisions(&revs);
609618
rollback_lock_file(&lock);
610-
return -1;
619+
return ret;
611620
}
612621

613622
int unbundle(struct repository *r, struct bundle_header *header,

t/t5605-clone-local.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='test local clone'
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
repo_is_hardlinked() {

t/t5607-clone-bundle.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='some bundle related tests'
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
test_expect_success 'setup' '

t/t6020-bundle-misc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_description='Test git-bundle'
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-bundle.sh
1314
. "$TEST_DIRECTORY"/lib-terminal.sh

0 commit comments

Comments
 (0)