]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git: fix leaking system paths
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:51:55 +0000 (08:51 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:07:56 +0000 (10:07 -0700)
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>
git.c

diff --git a/git.c b/git.c
index e35af9b0e5e976d43abbc490234d033b42542530..9a618a2740f1953e21bc18a49cc8db1ffb5dd4db 100644 (file)
--- a/git.c
+++ b/git.c
@@ -143,6 +143,13 @@ void setup_auto_pager(const char *cmd, int def)
        commit_pager_choice();
 }
 
+static void print_system_path(const char *path)
+{
+       char *s_path = system_path(path);
+       puts(s_path);
+       free(s_path);
+}
+
 static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
        const char **orig_argv = *argv;
@@ -173,15 +180,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                exit(0);
                        }
                } else if (!strcmp(cmd, "--html-path")) {
-                       puts(system_path(GIT_HTML_PATH));
+                       print_system_path(GIT_HTML_PATH);
                        trace2_cmd_name("_query_");
                        exit(0);
                } else if (!strcmp(cmd, "--man-path")) {
-                       puts(system_path(GIT_MAN_PATH));
+                       print_system_path(GIT_MAN_PATH);
                        trace2_cmd_name("_query_");
                        exit(0);
                } else if (!strcmp(cmd, "--info-path")) {
-                       puts(system_path(GIT_INFO_PATH));
+                       print_system_path(GIT_INFO_PATH);
                        trace2_cmd_name("_query_");
                        exit(0);
                } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {