]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rcxml.c: fix mem leak for repeated string config entries
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 15 Nov 2024 22:01:54 +0000 (23:01 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 16 Nov 2024 22:13:17 +0000 (22:13 +0000)
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()`.

src/config/rcxml.c

index ce77c8c0a5ca5f9ac43c666f2ea328f9173d4948..41b93a4caf41e4daaebcd056925c2bf1249fd430 100644 (file)
@@ -270,8 +270,7 @@ fill_usable_area_override(char *nodename, char *content)
        } else if (!current_usable_area_override) {
                wlr_log(WLR_ERROR, "no usable-area-override object");
        } else if (!strcmp(nodename, "output")) {
-               free(current_usable_area_override->output);
-               current_usable_area_override->output = xstrdup(content);
+               xstrdup_replace(current_usable_area_override->output, content);
        } else if (!strcmp(nodename, "left")) {
                current_usable_area_override->margin.left = atoi(content);
        } else if (!strcmp(nodename, "right")) {
@@ -320,21 +319,17 @@ fill_window_rule(char *nodename, char *content)
 
        /* Criteria */
        } else if (!strcmp(nodename, "identifier")) {
-               free(current_window_rule->identifier);
-               current_window_rule->identifier = xstrdup(content);
+               xstrdup_replace(current_window_rule->identifier, content);
        } else if (!strcmp(nodename, "title")) {
-               free(current_window_rule->title);
-               current_window_rule->title = xstrdup(content);
+               xstrdup_replace(current_window_rule->title, content);
        } else if (!strcmp(nodename, "type")) {
                current_window_rule->window_type = parse_window_type(content);
        } else if (!strcasecmp(nodename, "matchOnce")) {
                set_bool(content, &current_window_rule->match_once);
        } else if (!strcasecmp(nodename, "sandboxEngine")) {
-               free(current_window_rule->sandbox_engine);
-               current_window_rule->sandbox_engine = xstrdup(content);
+               xstrdup_replace(current_window_rule->sandbox_engine, content);
        } else if (!strcasecmp(nodename, "sandboxAppId")) {
-               free(current_window_rule->sandbox_app_id);
-               current_window_rule->sandbox_app_id = xstrdup(content);
+               xstrdup_replace(current_window_rule->sandbox_app_id, content);
 
        /* Event */
        } else if (!strcmp(nodename, "event")) {
@@ -464,15 +459,15 @@ fill_action_query(char *nodename, char *content, struct action *action)
        }
 
        if (!strcasecmp(nodename, "identifier")) {
-               current_view_query->identifier = xstrdup(content);
+               xstrdup_replace(current_view_query->identifier, content);
        } else if (!strcasecmp(nodename, "title")) {
-               current_view_query->title = xstrdup(content);
+               xstrdup_replace(current_view_query->title, content);
        } else if (!strcmp(nodename, "type")) {
                current_view_query->window_type = parse_window_type(content);
        } 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")) {
-               current_view_query->sandbox_app_id = xstrdup(content);
+               xstrdup_replace(current_view_query->sandbox_app_id, content);
        } else if (!strcasecmp(nodename, "shaded")) {
                current_view_query->shaded = parse_three_state(content);
        } else if (!strcasecmp(nodename, "maximized")) {
@@ -486,13 +481,13 @@ fill_action_query(char *nodename, char *content, struct action *action)
        } else if (!strcasecmp(nodename, "tiled")) {
                current_view_query->tiled = view_edge_parse(content);
        } 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")) {
-               current_view_query->desktop = xstrdup(content);
+               xstrdup_replace(current_view_query->desktop, content);
        } else if (!strcasecmp(nodename, "decoration")) {
                current_view_query->decoration = ssd_mode_parse(content);
        } 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);
                wl_list_append(&rc.touch_configs, &current_touch->link);
        } 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")) {
-               current_touch->output_name = xstrdup(content);
+               xstrdup_replace(current_touch->output_name, content);
        } else if (!strcasecmp(nodename, "mouseEmulation.touch")) {
                set_bool(content, &current_touch->force_mouse_emulation);
        } else {
@@ -735,7 +730,7 @@ fill_libinput_category(char *nodename, char *content)
                 * should be applicable to.
                 */
                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")) {
                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)
 {
        if (!strcmp(nodename, "name")) {
-               zfree(font->name);
-               font->name = xstrdup(content);
+               xstrdup_replace(font->name, content);
        } else if (!strcmp(nodename, "size")) {
                font->size = atoi(content);
        } else if (!strcmp(nodename, "slant")) {
@@ -1090,9 +1084,9 @@ entry(xmlNode *node, char *nodename, char *content)
        } else if (!strcasecmp(nodename, "y.cascadeOffset.placement")) {
                rc.placement_cascade_offset_y = atoi(content);
        } else if (!strcmp(nodename, "name.theme")) {
-               rc.theme_name = xstrdup(content);
+               xstrdup_replace(rc.theme_name, content);
        } 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")) {
                fill_title_layout(content);
        } else if (!strcasecmp(nodename, "showTitle.titlebar.theme")) {
@@ -1222,7 +1216,7 @@ entry(xmlNode *node, char *nodename, char *content)
        } else if (!strcasecmp(nodename, "number.desktops")) {
                rc.workspace_config.min_nr_workspaces = MAX(1, atoi(content));
        } 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")) {
                if (!strcasecmp(content, "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")) {
                set_bool(content, &rc.tablet.force_mouse_emulation);
        } 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")) {
                rc.tablet.rotation = tablet_parse_rotation(atoi(content));
        } else if (!strcasecmp(nodename, "left.area.tablet")) {