commit f4754bfb5a1f82158aa9119bdaa2cdb8b3bbf627
parent 3fb8efc8f2ea9bc33560c8c8681509a9a7fc95cd
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 23 Mar 2024 11:04:23 +0100
memory: prevent a leak by freeing a possibly already existing color combo
This fixes https://savannah.gnu.org/bugs/?65505.
Buglet existed in this form since version 2.9.3, commit 4b24ce1c.
Diffstat:
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -1229,16 +1229,16 @@ void parse_rule(char *ptr, int rex_flags)
}
}
-/* Parse the argument of an interface color option. */
-colortype *parse_interface_color(char *combostr)
+/* Set the colors for the given interface element to the given combination. */
+void set_interface_color(int element, char *combostring)
{
colortype *trio = nmalloc(sizeof(colortype));
- if (!parse_combination(combostr, &trio->fg, &trio->bg, &trio->attributes)) {
- free(trio);
- return NULL;
+ if (parse_combination(combostring, &trio->fg, &trio->bg, &trio->attributes)) {
+ free(color_combo[element]);
+ color_combo[element] = trio;
} else
- return trio;
+ free(trio);
}
/* Read regex strings enclosed in double quotes from the line pointed at
@@ -1583,29 +1583,29 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
#endif
#ifdef ENABLE_COLOR
if (strcmp(option, "titlecolor") == 0)
- color_combo[TITLE_BAR] = parse_interface_color(argument);
+ set_interface_color(TITLE_BAR, argument);
else if (strcmp(option, "numbercolor") == 0)
- color_combo[LINE_NUMBER] = parse_interface_color(argument);
+ set_interface_color(LINE_NUMBER, argument);
else if (strcmp(option, "stripecolor") == 0)
- color_combo[GUIDE_STRIPE] = parse_interface_color(argument);
+ set_interface_color(GUIDE_STRIPE, argument);
else if (strcmp(option, "scrollercolor") == 0)
- color_combo[SCROLL_BAR] = parse_interface_color(argument);
+ set_interface_color(SCROLL_BAR, argument);
else if (strcmp(option, "selectedcolor") == 0)
- color_combo[SELECTED_TEXT] = parse_interface_color(argument);
+ set_interface_color(SELECTED_TEXT, argument);
else if (strcmp(option, "spotlightcolor") == 0)
- color_combo[SPOTLIGHTED] = parse_interface_color(argument);
+ set_interface_color(SPOTLIGHTED, argument);
else if (strcmp(option, "minicolor") == 0)
- color_combo[MINI_INFOBAR] = parse_interface_color(argument);
+ set_interface_color(MINI_INFOBAR, argument);
else if (strcmp(option, "promptcolor") == 0)
- color_combo[PROMPT_BAR] = parse_interface_color(argument);
+ set_interface_color(PROMPT_BAR, argument);
else if (strcmp(option, "statuscolor") == 0)
- color_combo[STATUS_BAR] = parse_interface_color(argument);
+ set_interface_color(STATUS_BAR, argument);
else if (strcmp(option, "errorcolor") == 0)
- color_combo[ERROR_MESSAGE] = parse_interface_color(argument);
+ set_interface_color(ERROR_MESSAGE, argument);
else if (strcmp(option, "keycolor") == 0)
- color_combo[KEY_COMBO] = parse_interface_color(argument);
+ set_interface_color(KEY_COMBO, argument);
else if (strcmp(option, "functioncolor") == 0)
- color_combo[FUNCTION_TAG] = parse_interface_color(argument);
+ set_interface_color(FUNCTION_TAG, argument);
else
#endif
#ifdef ENABLE_OPERATINGDIR