]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config.c: don't leak memory in handle_path_include()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 21 Oct 2021 19:54:14 +0000 (21:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Oct 2021 23:26:45 +0000 (16:26 -0700)
Fix a memory leak in the error() path in handle_path_include(), this
allows us to run t1305-config-include.sh under SANITIZE=leak,
previously 4 tests there would fail. This fixes up a leak in
9b25a0b52e0 (config: add include directive, 2012-02-06).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
t/t1305-config-include.sh

index 2dcbe901b6b7a05f56a66056ac79d9b729454382..c5873f3a70643a9c03feeec4981a06a439e78118 100644 (file)
--- a/config.c
+++ b/config.c
@@ -148,8 +148,10 @@ static int handle_path_include(const char *path, struct config_include_data *inc
        if (!is_absolute_path(path)) {
                char *slash;
 
-               if (!cf || !cf->path)
-                       return error(_("relative config includes must come from files"));
+               if (!cf || !cf->path) {
+                       ret = error(_("relative config includes must come from files"));
+                       goto cleanup;
+               }
 
                slash = find_last_dir_sep(cf->path);
                if (slash)
@@ -167,6 +169,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
                ret = git_config_from_file(git_config_include, path, inc);
                inc->depth--;
        }
+cleanup:
        strbuf_release(&buf);
        free(expanded);
        return ret;
index ccbb116c0161d99d75f26cfa77d68e2ad7909ce8..5cde79ef8c4fa34b61eba75f98e827f05e2a27ab 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 test_description='test config file include directives'
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # Force setup_explicit_git_dir() to run until the end. This is needed