Skip to content

Commit ce15f9e

Browse files
pks-tgitster
authored andcommitted
git: fix leaking system paths
Git has some flags to make it output system paths as they have been compiled into Git. This is done by calling `system_path()`, which returns an allocated string. This string isn't ever free'd though, creating a memory leak. Plug those leaks. While they are surfaced by t0211, there are more memory leaks looming exposed by that test suite and it thus does not yet pass with the memory leak checker enabled. Helped-by: Taylor Blau <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce01f92 commit ce15f9e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

git.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ void setup_auto_pager(const char *cmd, int def)
143143
commit_pager_choice();
144144
}
145145

146+
static void print_system_path(const char *path)
147+
{
148+
char *s_path = system_path(path);
149+
puts(s_path);
150+
free(s_path);
151+
}
152+
146153
static int handle_options(const char ***argv, int *argc, int *envchanged)
147154
{
148155
const char **orig_argv = *argv;
@@ -173,15 +180,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
173180
exit(0);
174181
}
175182
} else if (!strcmp(cmd, "--html-path")) {
176-
puts(system_path(GIT_HTML_PATH));
183+
print_system_path(GIT_HTML_PATH);
177184
trace2_cmd_name("_query_");
178185
exit(0);
179186
} else if (!strcmp(cmd, "--man-path")) {
180-
puts(system_path(GIT_MAN_PATH));
187+
print_system_path(GIT_MAN_PATH);
181188
trace2_cmd_name("_query_");
182189
exit(0);
183190
} else if (!strcmp(cmd, "--info-path")) {
184-
puts(system_path(GIT_INFO_PATH));
191+
print_system_path(GIT_INFO_PATH);
185192
trace2_cmd_name("_query_");
186193
exit(0);
187194
} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {

0 commit comments

Comments
 (0)