hciemu: Fix crash when test is aborted during pre setup
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 11 Nov 2020 22:15:46 +0000 (14:15 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:33 +0000 (19:08 +0530)
If the tester_pre_setup_failed is called all timeout related to the
test must be cancelled as the test should have been freed by the
application and the next test is about to start.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
emulator/hciemu.c
src/shared/tester.c

index 9045cd5..62d11d4 100755 (executable)
@@ -42,6 +42,7 @@ struct hciemu {
        guint host_source;
        guint master_source;
        guint client_source;
+       guint start_source;
        struct queue *post_command_hooks;
        char bdaddr_str[18];
 
@@ -296,6 +297,8 @@ static gboolean start_stack(gpointer user_data)
 {
        struct hciemu *hciemu = user_data;
 
+       hciemu->start_source = 0;
+
        bthost_start(hciemu->host_stack);
 
        return FALSE;
@@ -352,7 +355,7 @@ struct hciemu *hciemu_new(enum hciemu_type type)
                return NULL;
        }
 
-       g_idle_add(start_stack, hciemu);
+       hciemu->start_source = g_idle_add(start_stack, hciemu);
 
        return hciemu_ref(hciemu);
 }
@@ -377,6 +380,9 @@ void hciemu_unref(struct hciemu *hciemu)
 
        queue_destroy(hciemu->post_command_hooks, destroy_command_hook);
 
+       if (hciemu->start_source)
+               g_source_remove(hciemu->start_source);
+
        g_source_remove(hciemu->host_source);
        g_source_remove(hciemu->client_source);
        g_source_remove(hciemu->master_source);
index 7c19bbb..e65eb5b 100755 (executable)
@@ -540,6 +540,11 @@ void tester_pre_setup_failed(void)
        if (test->stage != TEST_STAGE_PRE_SETUP)
                return;
 
+       if (test->timeout_id > 0) {
+               g_source_remove(test->timeout_id);
+               test->timeout_id = 0;
+       }
+
        print_progress(test->name, COLOR_RED, "pre setup failed");
 
        g_idle_add(done_callback, test);