]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/test-repository: fix leaking repository
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2024 10:40:56 +0000 (12:40 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Aug 2024 15:47:37 +0000 (08:47 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-repository.c
t/t5318-commit-graph.sh

index c6a074df3d2d94a2c039365fb897768df6e18696..63c37de33d22f195bb15298527e013e98c778776 100644 (file)
@@ -19,7 +19,7 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
 
        setup_git_env(gitdir);
 
-       memset(the_repository, 0, sizeof(*the_repository));
+       repo_clear(the_repository);
 
        if (repo_init(&r, gitdir, worktree))
                die("Couldn't init repo");
@@ -49,7 +49,7 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
 
        setup_git_env(gitdir);
 
-       memset(the_repository, 0, sizeof(*the_repository));
+       repo_clear(the_repository);
 
        if (repo_init(&r, gitdir, worktree))
                die("Couldn't init repo");
index a2b44426609fe5c52347510e8b82c9484897dea8..2916c07e3c2490e7af5eb05cfe62f90e4c7c359a 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='commit graph'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-chunk.sh