Skip to content

Commit 2a2d5da

Browse files
pks-tgitster
authored andcommitted
sideband: fix leaks when configuring sideband colors
We read a bunch of configs in `use_sideband_colors()` to configure the colors that Git should use. We never free the strings read from the config though, causing memory leaks. Refactor the code to use `git_config_get_string_tmp()` instead, which does not allocate memory. As we throw the strings away after parsing them anyway there is no need to use allocated strings. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a09efb7 commit 2a2d5da

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

sideband.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,27 @@ static int use_sideband_colors(void)
3030

3131
const char *key = "color.remote";
3232
struct strbuf sb = STRBUF_INIT;
33-
char *value;
33+
const char *value;
3434
int i;
3535

3636
if (use_sideband_colors_cached >= 0)
3737
return use_sideband_colors_cached;
3838

39-
if (!git_config_get_string(key, &value)) {
39+
if (!git_config_get_string_tmp(key, &value))
4040
use_sideband_colors_cached = git_config_colorbool(key, value);
41-
} else if (!git_config_get_string("color.ui", &value)) {
41+
else if (!git_config_get_string_tmp("color.ui", &value))
4242
use_sideband_colors_cached = git_config_colorbool("color.ui", value);
43-
} else {
43+
else
4444
use_sideband_colors_cached = GIT_COLOR_AUTO;
45-
}
4645

4746
for (i = 0; i < ARRAY_SIZE(keywords); i++) {
4847
strbuf_reset(&sb);
4948
strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword);
50-
if (git_config_get_string(sb.buf, &value))
51-
continue;
52-
if (color_parse(value, keywords[i].color))
49+
if (git_config_get_string_tmp(sb.buf, &value))
5350
continue;
51+
color_parse(value, keywords[i].color);
5452
}
53+
5554
strbuf_release(&sb);
5655
return use_sideband_colors_cached;
5756
}

t/t5409-colorize-remote-messages.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='remote messages are colorized on the client'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success 'setup' '

0 commit comments

Comments
 (0)