diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2021-06-16 12:04:24 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2021-06-16 12:04:24 -0400 |
commit | c2d2baf3e00fbedf213ca730a5931c236acfede7 (patch) | |
tree | d853db65538139b697b3d855bccb18776a6d9bd6 /color.c | |
parent | f0bae86b684e57065da737ed5c8744f3757e9d38 (diff) | |
download | bfs-c2d2baf3e00fbedf213ca730a5931c236acfede7.tar.xz |
color: Fix a leak on unknown color keys
Previously reproducible with LS_COLORS="asdf=0" bfs.
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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); } } |