summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-06-16 12:04:24 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-06-16 12:04:24 -0400
commitc2d2baf3e00fbedf213ca730a5931c236acfede7 (patch)
treed853db65538139b697b3d855bccb18776a6d9bd6 /color.c
parentf0bae86b684e57065da737ed5c8744f3757e9d38 (diff)
downloadbfs-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.c9
1 files 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);
}
}