[PATCH weston v5 08/36] libweston: strdup head make, model, serial_number
Pekka Paalanen
ppaalanen at gmail.com
Thu Dec 14 11:40:45 UTC 2017
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Duplicate these strings to decouple their lifetime from whatever the
backends used. This should prevent hard to catch use after frees and
such problems in the future.
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
libweston/compositor.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/libweston/compositor.c b/libweston/compositor.c
index d314f2d5..1e62254a 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -4501,6 +4501,10 @@ static void
weston_head_release(struct weston_head *head)
{
weston_head_detach(head);
+
+ free(head->make);
+ free(head->model);
+ free(head->serial_number);
}
/** Store monitor make, model and serial number
@@ -4522,9 +4526,13 @@ weston_head_set_monitor_strings(struct weston_head *head,
const char *model,
const char *serialno)
{
- head->make = (char *)make;
- head->model = (char *)model;
- head->serial_number = (char *)serialno;
+ free(head->make);
+ free(head->model);
+ free(head->serial_number);
+
+ head->make = make ? strdup(make) : NULL;
+ head->model = model ? strdup(model) : NULL;
+ head->serial_number = serialno ? strdup(serialno) : NULL;
}
/** Store physical image size
--
2.13.6
More information about the wayland-devel
mailing list