Skip to content

Commit 71c848b

Browse files
committed
Merge branch 'js/runtime-prefix'
* js/runtime-prefix: Avoid multiple PREFIX definitions git_setup_gettext: plug memory leak gettext: avoid initialization if the locale dir is not present
2 parents a56fb3d + 4d5b4c2 commit 71c848b

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,7 @@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \
22842284
'-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
22852285
'-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
22862286
'-DBINDIR="$(bindir_relative_SQ)"' \
2287-
'-DPREFIX="$(prefix_SQ)"'
2287+
'-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
22882288

22892289
builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
22902290
builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \

exec-cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static const char *system_prefix(void)
4848
!(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) &&
4949
!(prefix = strip_path_suffix(executable_dirname, BINDIR)) &&
5050
!(prefix = strip_path_suffix(executable_dirname, "git"))) {
51-
prefix = PREFIX;
51+
prefix = FALLBACK_RUNTIME_PREFIX;
5252
trace_printf("RUNTIME_PREFIX requested, "
5353
"but prefix computation failed. "
5454
"Using static fallback '%s'.\n", prefix);
@@ -243,7 +243,7 @@ void git_resolve_executable_dir(const char *argv0)
243243
*/
244244
static const char *system_prefix(void)
245245
{
246-
return PREFIX;
246+
return FALLBACK_RUNTIME_PREFIX;
247247
}
248248

249249
/*

gettext.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,23 @@ static void init_gettext_charset(const char *domain)
159159
void git_setup_gettext(void)
160160
{
161161
const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);
162+
char *p = NULL;
162163

163164
if (!podir)
164-
podir = system_path(GIT_LOCALE_PATH);
165+
podir = p = system_path(GIT_LOCALE_PATH);
166+
167+
if (!is_directory(podir)) {
168+
free(p);
169+
return;
170+
}
165171

166172
bindtextdomain("git", podir);
167173
setlocale(LC_MESSAGES, "");
168174
setlocale(LC_TIME, "");
169175
init_gettext_charset("git");
170176
textdomain("git");
177+
178+
free(p);
171179
}
172180

173181
/* return the number of columns of string 's' in current locale */

sideband.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* the remote died unexpectedly. A flush() concludes the stream.
1414
*/
1515

16-
#define PREFIX "remote: "
16+
#define DISPLAY_PREFIX "remote: "
1717

1818
#define ANSI_SUFFIX "\033[K"
1919
#define DUMB_SUFFIX " "
@@ -49,7 +49,7 @@ int recv_sideband(const char *me, int in_stream, int out)
4949
switch (band) {
5050
case 3:
5151
strbuf_addf(&outbuf, "%s%s%s", outbuf.len ? "\n" : "",
52-
PREFIX, buf + 1);
52+
DISPLAY_PREFIX, buf + 1);
5353
retval = SIDEBAND_REMOTE_ERROR;
5454
break;
5555
case 2:
@@ -67,7 +67,7 @@ int recv_sideband(const char *me, int in_stream, int out)
6767
int linelen = brk - b;
6868

6969
if (!outbuf.len)
70-
strbuf_addstr(&outbuf, PREFIX);
70+
strbuf_addstr(&outbuf, DISPLAY_PREFIX);
7171
if (linelen > 0) {
7272
strbuf_addf(&outbuf, "%.*s%s%c",
7373
linelen, b, suffix, *brk);
@@ -81,8 +81,8 @@ int recv_sideband(const char *me, int in_stream, int out)
8181
}
8282

8383
if (*b)
84-
strbuf_addf(&outbuf, "%s%s",
85-
outbuf.len ? "" : PREFIX, b);
84+
strbuf_addf(&outbuf, "%s%s", outbuf.len ?
85+
"" : DISPLAY_PREFIX, b);
8686
break;
8787
case 1:
8888
write_or_die(out, buf + 1, len);

0 commit comments

Comments
 (0)