git_setup_gettext: plug memory leak

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>

Johannes Schindelin committed Apr 21, 2018 at 13:14 UTC 0210231b0803f881bf765bb2d7284c119c6ce9b6
1 file changed +7 -2
gettext.c
+7 -2
@@ -159,18 +159,23 @@ static void init_gettext_charset(const char *domain)
159 void git_setup_gettext(void)
160 {
161 const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);
162 + char *p = NULL;
163
164 if (!podir)
164 - podir = system_path(GIT_LOCALE_PATH);
165 + podir = p = system_path(GIT_LOCALE_PATH);
166
166 - if (!is_directory(podir))
167 + if (!is_directory(podir)) {
168 + free(p);
169 return;
170 + }
171
172 bindtextdomain("git", podir);
173 setlocale(LC_MESSAGES, "");
174 setlocale(LC_TIME, "");
175 init_gettext_charset("git");
176 textdomain("git");
177 +
178 + free(p);
179 }
180
181 /* return the number of columns of string 's' in current locale */