]> Kevux Git Server - rit/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 dfc3c3e..dda4582 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 9fdafeb..f31c09c 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 120dcd7..794bc7d 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' '