[PATCH 13/20] sideband: fix leaks when configuring sideband colors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. Fix those.

Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
---
 sideband.c                          | 8 +++++---
 t/t5409-colorize-remote-messages.sh | 1 +
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/sideband.c b/sideband.c
index 5d8907151fe..deb6ec0a8b7 100644
--- a/sideband.c
+++ b/sideband.c
@@ -30,7 +30,7 @@ static int use_sideband_colors(void)
 
 	const char *key = "color.remote";
 	struct strbuf sb = STRBUF_INIT;
-	char *value;
+	char *value = NULL;
 	int i;
 
 	if (use_sideband_colors_cached >= 0)
@@ -43,15 +43,17 @@ static int use_sideband_colors(void)
 	} else {
 		use_sideband_colors_cached = GIT_COLOR_AUTO;
 	}
+	FREE_AND_NULL(value);
 
 	for (i = 0; i < ARRAY_SIZE(keywords); i++) {
 		strbuf_reset(&sb);
 		strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword);
 		if (git_config_get_string(sb.buf, &value))
 			continue;
-		if (color_parse(value, keywords[i].color))
-			continue;
+		color_parse(value, keywords[i].color);
+		FREE_AND_NULL(value);
 	}
+
 	strbuf_release(&sb);
 	return use_sideband_colors_cached;
 }
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index fa5de4500a4..516b22fd963 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -2,6 +2,7 @@
 
 test_description='remote messages are colorized on the client'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-- 
2.46.0.164.g477ce5ccd6.dirty





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux