From c2d2baf3e00fbedf213ca730a5931c236acfede7 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 16 Jun 2021 12:04:24 -0400 Subject: color: Fix a leak on unknown color keys Previously reproducible with LS_COLORS="asdf=0" bfs. --- color.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/color.c b/color.c index f04bdf5..509e646 100644 --- a/color.c +++ b/color.c @@ -120,11 +120,14 @@ static char **get_color(const struct colors *colors, const char *name) { } /** Set the value of a color. */ -static void set_color(struct colors *colors, const char *name, char *value) { +static int set_color(struct colors *colors, const char *name, char *value) { char **color = get_color(colors, name); if (color) { dstrfree(*color); *color = value; + return 0; + } else { + return -1; } } @@ -462,7 +465,9 @@ struct colors *parse_colors(const char *ls_colors) { value = NULL; } - set_color(colors, key, value); + if (set_color(colors, key, value) != 0) { + dstrfree(value); + } free(key); } } -- cgit v1.2.3