From 06f99efc9c417eefb8046bf64a84869d698a0be5 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 4 Apr 2017 16:26:23 +0300 Subject: [PATCH] libweston: strdup head make, model, serial_number 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 v5 Reviewed-by: Derek Foreman Reviewed-by: Ian Ray Reviewed-by: Daniel Stone Acked-by: Derek Foreman --- libweston/compositor.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libweston/compositor.c b/libweston/compositor.c index 767cb80..c3a94d3 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -4511,6 +4511,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 @@ -4532,9 +4536,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.7.4