From 44a166dde80d7bf4fa843b1da760bfc8de25c0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 7 Apr 2021 08:04:24 +0200 Subject: [PATCH] wayland: {xdg_,}output_*(): free old strings before assigning new ones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- wayland.c | 7 +++++++ 1 file changed, 7 insertions(+) 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; }