git_setup_gettext: plug memory leak
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sat, 21 Apr 2018 11:14:28 +0000 (13:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Apr 2018 02:12:32 +0000 (11:12 +0900)
The system_path() function returns a freshly-allocated string. We need
to release it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gettext.c
index 3eb20c5f958930aec2a399c1688545e0996a927f..4f59dfa3d14e2d84ad3def9f9670dcc1c42d2db6 100644 (file)
--- a/gettext.c
+++ b/gettext.c
@@ -159,18 +159,23 @@ static void init_gettext_charset(const char *domain)
 void git_setup_gettext(void)
 {
        const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);
+       char *p = NULL;
 
        if (!podir)
-               podir = system_path(GIT_LOCALE_PATH);
+               podir = p = system_path(GIT_LOCALE_PATH);
 
-       if (!is_directory(podir))
+       if (!is_directory(podir)) {
+               free(p);
                return;
+       }
 
        bindtextdomain("git", podir);
        setlocale(LC_MESSAGES, "");
        setlocale(LC_TIME, "");
        init_gettext_charset("git");
        textdomain("git");
+
+       free(p);
 }
 
 /* return the number of columns of string 's' in current locale */