]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/grep: fix leaking object context
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Sep 2024 10:09:31 +0000 (12:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2024 15:49:12 +0000 (08:49 -0700)
Even when `get_oid_with_context()` fails it may have allocated some data
in the object context. But we do not release it in git-grep(1) when the
call fails, leading to a memory leak. Plug it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
t/t6132-pathspec-exclude.sh
t/t6135-pathspec-with-attrs.sh

index dfc3c3e8bd28a009cdf4a4f7b95ab63588140a7f..dda4582d6469066494931d8279ffb24c5e8c75ae 100644 (file)
@@ -1133,6 +1133,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                                         &oid, &oc)) {
                        if (seen_dashdash)
                                die(_("unable to resolve revision: %s"), arg);
+                       object_context_release(&oc);
                        break;
                }
 
index 9fdafeb1e907f4381f2b1e74c6c00771d188d136..f31c09c056fc6c7010be2d5c219ceaa2249f50b0 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='test case exclude pathspec'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index 120dcd74a51434303b8bd7e71d10a9cb120bf574..794bc7daf050472229622781044a87140946a046 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='test labels in pathspecs'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup a tree' '