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 <me@ttaylorr.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 14, 2024 at 08:51 UTC ce15f9eb9eb9e7ac3d5095b19cd7b8c7c5bfc22b
1 file changed +10 -3
git.c
+10 -3
@@ -143,6 +143,13 @@ void setup_auto_pager(const char *cmd, int def)
143 commit_pager_choice();
144 }
145
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 +
153 static int handle_options(const char ***argv, int *argc, int *envchanged)
154 {
155 const char **orig_argv = *argv;
@@ -173,15 +180,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
180 exit(0);
181 }
182 } else if (!strcmp(cmd, "--html-path")) {
176 - puts(system_path(GIT_HTML_PATH));
183 + print_system_path(GIT_HTML_PATH);
184 trace2_cmd_name("_query_");
185 exit(0);
186 } else if (!strcmp(cmd, "--man-path")) {
180 - puts(system_path(GIT_MAN_PATH));
187 + print_system_path(GIT_MAN_PATH);
188 trace2_cmd_name("_query_");
189 exit(0);
190 } else if (!strcmp(cmd, "--info-path")) {
184 - puts(system_path(GIT_INFO_PATH));
191 + print_system_path(GIT_INFO_PATH);
192 trace2_cmd_name("_query_");
193 exit(0);
194 } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {