Skip to content

Commit 11f841c

Browse files
pks-tgitster
authored andcommitted
t/test-repository: fix leaking repository
The test-repository test helper zeroes out `the_repository` such that it can be sure that our codebase only ends up using the supplied repository that we initialize in the respective helper functions. This does cause memory leaks though as the data that `the_repository` has been holding onto is not referenced anymore. Fix this by calling `repo_clear()` instead. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 145c979 commit 11f841c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

t/helper/test-repository.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
1919

2020
setup_git_env(gitdir);
2121

22-
memset(the_repository, 0, sizeof(*the_repository));
22+
repo_clear(the_repository);
2323

2424
if (repo_init(&r, gitdir, worktree))
2525
die("Couldn't init repo");
@@ -49,7 +49,7 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
4949

5050
setup_git_env(gitdir);
5151

52-
memset(the_repository, 0, sizeof(*the_repository));
52+
repo_clear(the_repository);
5353

5454
if (repo_init(&r, gitdir, worktree))
5555
die("Couldn't init repo");

t/t5318-commit-graph.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='commit graph'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57
. "$TEST_DIRECTORY"/lib-chunk.sh
68

0 commit comments

Comments
 (0)