aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-04-07 06:04:24 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-04-18 18:07:24 +0000
commit407189978ee0a8bcdc78d5eab6a04ea25526e531 (patch)
tree7c55fe20d3c0be2411c3581422b9c3b0d7c444a8
parentchangelog: move OSC-4/104 fix from 1.7.1 to ‘unreleased’ (diff)
wayland: {xdg_,}output_*(): free old strings before assigning new ones
Defensive programming; output_geometry() etc are typically only called once for an output instance. But let’s ensure we’re not leaking memory if it’s called more than once.
-rw-r--r--wayland.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/wayland.c b/wayland.c
index edc9b482..8985e119 100644
--- a/wayland.c
+++ b/wayland.c
@@ -359,6 +359,10 @@ output_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y,
int32_t transform)
{
struct monitor *mon = data;
+
+ free(mon->make);
+ free(mon->model);
+
mon->dim.mm.width = physical_width;
mon->dim.mm.height = physical_height;
mon->inch = sqrt(pow(mon->dim.mm.width, 2) + pow(mon->dim.mm.height, 2)) * 0.03937008;
@@ -366,6 +370,7 @@ output_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y,
mon->model = model != NULL ? xstrdup(model) : NULL;
mon->subpixel = subpixel;
mon->transform = transform;
+
output_update_ppi(mon);
}
@@ -434,6 +439,7 @@ xdg_output_handle_name(void *data, struct zxdg_output_v1 *xdg_output,
const char *name)
{
struct monitor *mon = data;
+ free(mon->name);
mon->name = name != NULL ? xstrdup(name) : NULL;
}
@@ -442,6 +448,7 @@ xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output,
const char *description)
{
struct monitor *mon = data;
+ free(mon->description);
mon->description = description != NULL ? xstrdup(description) : NULL;
}