From 29d2f61e727cb13cbb3df6308d1f87a2a610ab18 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Tue, 13 Nov 2018 13:44:24 +0200 Subject: [PATCH] [worker] Use copy of target mode during transition. JB#43781 The common_map_mode_to_hardware() function can return the same string that it was given as an argument. In the context of worker_execute() function this can lead to using string pointer that can get invalidated after releasing mutex. Allocate copy of target mode before releasing mutex and use it in the subsequent operations. Signed-off-by: Simo Piiroinen --- src/usb_moded-worker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/usb_moded-worker.c b/src/usb_moded-worker.c index b5e422c..bf2c4ae 100644 --- a/src/usb_moded-worker.c +++ b/src/usb_moded-worker.c @@ -468,14 +468,17 @@ worker_execute(void) log_debug("activate = %s", activate); bool changed = g_strcmp0(activated, activate) != 0; + gchar *mode = g_strdup(activate); WORKER_LOCKED_LEAVE; if( changed ) - worker_switch_to_mode(activate); + worker_switch_to_mode(mode); else worker_notify(); + g_free(mode); + return; }