rcxml.c: fix mem leak for repeated string config entries

An example is
```xml
<theme>
  <name>Numix</name>
</theme>
<theme name="Numix" />
```

Including various other variants.
Also change all other `free(x); x = xstrdup(y)` calls to `xstrdup_replace()`.
This commit is contained in:
Consolatis 2024-11-15 23:01:54 +01:00 committed by Johan Malm
parent a4204d3335
commit 5c9cae71cd

View file

@ -270,8 +270,7 @@ fill_usable_area_override(char *nodename, char *content)
} else if (!current_usable_area_override) { } else if (!current_usable_area_override) {
wlr_log(WLR_ERROR, "no usable-area-override object"); wlr_log(WLR_ERROR, "no usable-area-override object");
} else if (!strcmp(nodename, "output")) { } else if (!strcmp(nodename, "output")) {
free(current_usable_area_override->output); xstrdup_replace(current_usable_area_override->output, content);
current_usable_area_override->output = xstrdup(content);
} else if (!strcmp(nodename, "left")) { } else if (!strcmp(nodename, "left")) {
current_usable_area_override->margin.left = atoi(content); current_usable_area_override->margin.left = atoi(content);
} else if (!strcmp(nodename, "right")) { } else if (!strcmp(nodename, "right")) {
@ -320,21 +319,17 @@ fill_window_rule(char *nodename, char *content)
/* Criteria */ /* Criteria */
} else if (!strcmp(nodename, "identifier")) { } else if (!strcmp(nodename, "identifier")) {
free(current_window_rule->identifier); xstrdup_replace(current_window_rule->identifier, content);
current_window_rule->identifier = xstrdup(content);
} else if (!strcmp(nodename, "title")) { } else if (!strcmp(nodename, "title")) {
free(current_window_rule->title); xstrdup_replace(current_window_rule->title, content);
current_window_rule->title = xstrdup(content);
} else if (!strcmp(nodename, "type")) { } else if (!strcmp(nodename, "type")) {
current_window_rule->window_type = parse_window_type(content); current_window_rule->window_type = parse_window_type(content);
} else if (!strcasecmp(nodename, "matchOnce")) { } else if (!strcasecmp(nodename, "matchOnce")) {
set_bool(content, &current_window_rule->match_once); set_bool(content, &current_window_rule->match_once);
} else if (!strcasecmp(nodename, "sandboxEngine")) { } else if (!strcasecmp(nodename, "sandboxEngine")) {
free(current_window_rule->sandbox_engine); xstrdup_replace(current_window_rule->sandbox_engine, content);
current_window_rule->sandbox_engine = xstrdup(content);
} else if (!strcasecmp(nodename, "sandboxAppId")) { } else if (!strcasecmp(nodename, "sandboxAppId")) {
free(current_window_rule->sandbox_app_id); xstrdup_replace(current_window_rule->sandbox_app_id, content);
current_window_rule->sandbox_app_id = xstrdup(content);
/* Event */ /* Event */
} else if (!strcmp(nodename, "event")) { } else if (!strcmp(nodename, "event")) {
@ -464,15 +459,15 @@ fill_action_query(char *nodename, char *content, struct action *action)
} }
if (!strcasecmp(nodename, "identifier")) { if (!strcasecmp(nodename, "identifier")) {
current_view_query->identifier = xstrdup(content); xstrdup_replace(current_view_query->identifier, content);
} else if (!strcasecmp(nodename, "title")) { } else if (!strcasecmp(nodename, "title")) {
current_view_query->title = xstrdup(content); xstrdup_replace(current_view_query->title, content);
} else if (!strcmp(nodename, "type")) { } else if (!strcmp(nodename, "type")) {
current_view_query->window_type = parse_window_type(content); current_view_query->window_type = parse_window_type(content);
} else if (!strcasecmp(nodename, "sandboxEngine")) { } else if (!strcasecmp(nodename, "sandboxEngine")) {
current_view_query->sandbox_engine = xstrdup(content); xstrdup_replace(current_view_query->sandbox_engine, content);
} else if (!strcasecmp(nodename, "sandboxAppId")) { } else if (!strcasecmp(nodename, "sandboxAppId")) {
current_view_query->sandbox_app_id = xstrdup(content); xstrdup_replace(current_view_query->sandbox_app_id, content);
} else if (!strcasecmp(nodename, "shaded")) { } else if (!strcasecmp(nodename, "shaded")) {
current_view_query->shaded = parse_three_state(content); current_view_query->shaded = parse_three_state(content);
} else if (!strcasecmp(nodename, "maximized")) { } else if (!strcasecmp(nodename, "maximized")) {
@ -486,13 +481,13 @@ fill_action_query(char *nodename, char *content, struct action *action)
} else if (!strcasecmp(nodename, "tiled")) { } else if (!strcasecmp(nodename, "tiled")) {
current_view_query->tiled = view_edge_parse(content); current_view_query->tiled = view_edge_parse(content);
} else if (!strcasecmp(nodename, "tiled_region")) { } else if (!strcasecmp(nodename, "tiled_region")) {
current_view_query->tiled_region = xstrdup(content); xstrdup_replace(current_view_query->tiled_region, content);
} else if (!strcasecmp(nodename, "desktop")) { } else if (!strcasecmp(nodename, "desktop")) {
current_view_query->desktop = xstrdup(content); xstrdup_replace(current_view_query->desktop, content);
} else if (!strcasecmp(nodename, "decoration")) { } else if (!strcasecmp(nodename, "decoration")) {
current_view_query->decoration = ssd_mode_parse(content); current_view_query->decoration = ssd_mode_parse(content);
} else if (!strcasecmp(nodename, "monitor")) { } else if (!strcasecmp(nodename, "monitor")) {
current_view_query->monitor = xstrdup(content); xstrdup_replace(current_view_query->monitor, content);
} }
} }
@ -650,9 +645,9 @@ fill_touch(char *nodename, char *content)
current_touch = znew(*current_touch); current_touch = znew(*current_touch);
wl_list_append(&rc.touch_configs, &current_touch->link); wl_list_append(&rc.touch_configs, &current_touch->link);
} else if (!strcasecmp(nodename, "deviceName.touch")) { } else if (!strcasecmp(nodename, "deviceName.touch")) {
current_touch->device_name = xstrdup(content); xstrdup_replace(current_touch->device_name, content);
} else if (!strcasecmp(nodename, "mapToOutput.touch")) { } else if (!strcasecmp(nodename, "mapToOutput.touch")) {
current_touch->output_name = xstrdup(content); xstrdup_replace(current_touch->output_name, content);
} else if (!strcasecmp(nodename, "mouseEmulation.touch")) { } else if (!strcasecmp(nodename, "mouseEmulation.touch")) {
set_bool(content, &current_touch->force_mouse_emulation); set_bool(content, &current_touch->force_mouse_emulation);
} else { } else {
@ -735,7 +730,7 @@ fill_libinput_category(char *nodename, char *content)
* should be applicable to. * should be applicable to.
*/ */
if (current_libinput_category->type == LAB_LIBINPUT_DEVICE_NONE) { if (current_libinput_category->type == LAB_LIBINPUT_DEVICE_NONE) {
current_libinput_category->name = xstrdup(content); xstrdup_replace(current_libinput_category->name, content);
} }
} else if (!strcasecmp(nodename, "naturalScroll")) { } else if (!strcasecmp(nodename, "naturalScroll")) {
set_bool_as_int(content, &current_libinput_category->natural_scroll); set_bool_as_int(content, &current_libinput_category->natural_scroll);
@ -850,8 +845,7 @@ static void
set_font_attr(struct font *font, const char *nodename, const char *content) set_font_attr(struct font *font, const char *nodename, const char *content)
{ {
if (!strcmp(nodename, "name")) { if (!strcmp(nodename, "name")) {
zfree(font->name); xstrdup_replace(font->name, content);
font->name = xstrdup(content);
} else if (!strcmp(nodename, "size")) { } else if (!strcmp(nodename, "size")) {
font->size = atoi(content); font->size = atoi(content);
} else if (!strcmp(nodename, "slant")) { } else if (!strcmp(nodename, "slant")) {
@ -1090,9 +1084,9 @@ entry(xmlNode *node, char *nodename, char *content)
} else if (!strcasecmp(nodename, "y.cascadeOffset.placement")) { } else if (!strcasecmp(nodename, "y.cascadeOffset.placement")) {
rc.placement_cascade_offset_y = atoi(content); rc.placement_cascade_offset_y = atoi(content);
} else if (!strcmp(nodename, "name.theme")) { } else if (!strcmp(nodename, "name.theme")) {
rc.theme_name = xstrdup(content); xstrdup_replace(rc.theme_name, content);
} else if (!strcmp(nodename, "icon.theme")) { } else if (!strcmp(nodename, "icon.theme")) {
rc.icon_theme_name = xstrdup(content); xstrdup_replace(rc.icon_theme_name, content);
} else if (!strcasecmp(nodename, "layout.titlebar.theme")) { } else if (!strcasecmp(nodename, "layout.titlebar.theme")) {
fill_title_layout(content); fill_title_layout(content);
} else if (!strcasecmp(nodename, "showTitle.titlebar.theme")) { } else if (!strcasecmp(nodename, "showTitle.titlebar.theme")) {
@ -1222,7 +1216,7 @@ entry(xmlNode *node, char *nodename, char *content)
} else if (!strcasecmp(nodename, "number.desktops")) { } else if (!strcasecmp(nodename, "number.desktops")) {
rc.workspace_config.min_nr_workspaces = MAX(1, atoi(content)); rc.workspace_config.min_nr_workspaces = MAX(1, atoi(content));
} else if (!strcasecmp(nodename, "prefix.desktops")) { } else if (!strcasecmp(nodename, "prefix.desktops")) {
rc.workspace_config.prefix = xstrdup(content); xstrdup_replace(rc.workspace_config.prefix, content);
} else if (!strcasecmp(nodename, "popupShow.resize")) { } else if (!strcasecmp(nodename, "popupShow.resize")) {
if (!strcasecmp(content, "Always")) { if (!strcasecmp(content, "Always")) {
rc.resize_indicator = LAB_RESIZE_INDICATOR_ALWAYS; rc.resize_indicator = LAB_RESIZE_INDICATOR_ALWAYS;
@ -1238,7 +1232,7 @@ entry(xmlNode *node, char *nodename, char *content)
} else if (!strcasecmp(nodename, "mouseEmulation.tablet")) { } else if (!strcasecmp(nodename, "mouseEmulation.tablet")) {
set_bool(content, &rc.tablet.force_mouse_emulation); set_bool(content, &rc.tablet.force_mouse_emulation);
} else if (!strcasecmp(nodename, "mapToOutput.tablet")) { } else if (!strcasecmp(nodename, "mapToOutput.tablet")) {
rc.tablet.output_name = xstrdup(content); xstrdup_replace(rc.tablet.output_name, content);
} else if (!strcasecmp(nodename, "rotate.tablet")) { } else if (!strcasecmp(nodename, "rotate.tablet")) {
rc.tablet.rotation = tablet_parse_rotation(atoi(content)); rc.tablet.rotation = tablet_parse_rotation(atoi(content));
} else if (!strcasecmp(nodename, "left.area.tablet")) { } else if (!strcasecmp(nodename, "left.area.tablet")) {