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.
This commit is contained in:
Daniel Eklöf 2021-04-07 08:04:24 +02:00
parent e299b1d9f4
commit 44a166dde8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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;
}