Skip to content

Commit 25ad722

Browse files
avargitster
authored andcommitted
config.c: don't leak memory in handle_path_include()
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 9b25a0b (config: add include directive, 2012-02-06). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d530dc commit 25ad722

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

config.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ static int handle_path_include(const char *path, struct config_include_data *inc
148148
if (!is_absolute_path(path)) {
149149
char *slash;
150150

151-
if (!cf || !cf->path)
152-
return error(_("relative config includes must come from files"));
151+
if (!cf || !cf->path) {
152+
ret = error(_("relative config includes must come from files"));
153+
goto cleanup;
154+
}
153155

154156
slash = find_last_dir_sep(cf->path);
155157
if (slash)
@@ -167,6 +169,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
167169
ret = git_config_from_file(git_config_include, path, inc);
168170
inc->depth--;
169171
}
172+
cleanup:
170173
strbuf_release(&buf);
171174
free(expanded);
172175
return ret;

t/t1305-config-include.sh

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

33
test_description='test config file include directives'
4+
TEST_PASSES_SANITIZE_LEAK=true
45
. ./test-lib.sh
56

67
# Force setup_explicit_git_dir() to run until the end. This is needed

0 commit comments

Comments
 (0)