diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-03-10 15:24:09 +0200 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2015-03-11 12:21:00 +0200 |
commit | 075ddc4423b3d204c422d5f7ad2f926dc895bcb3 (patch) | |
tree | 2a21022683385163f5f67bba20af7483eae3ed4e | |
parent | 6b91a808f18125aa47f91ef2152c8e79bbb54c55 (diff) | |
download | bluez-075ddc4423b3d204c422d5f7ad2f926dc895bcb3.tar.gz |
shared/tester: Fix teardown multiple times
tester_test* can be called multiple times which cause teardown callback
to be called multiple times as well leading to to crashes or strange
behavior.
-rw-r--r-- | src/shared/tester.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/shared/tester.c b/src/shared/tester.c index acd3df7e5..d05bf08b6 100644 --- a/src/shared/tester.c +++ b/src/shared/tester.c @@ -90,6 +90,7 @@ struct test_case { gdouble end_time; unsigned int timeout; unsigned int timeout_id; + unsigned int teardown_id; tester_destroy_func_t destroy; void *user_data; }; @@ -113,6 +114,9 @@ static void test_destroy(gpointer data) if (test->timeout_id > 0) g_source_remove(test->timeout_id); + if (test->teardown_id > 0) + g_source_remove(test->teardown_id); + if (test->destroy) test->destroy(test->user_data); @@ -328,6 +332,7 @@ static gboolean teardown_callback(gpointer user_data) { struct test_case *test = user_data; + test->teardown_id = 0; test->stage = TEST_STAGE_TEARDOWN; print_progress(test->name, COLOR_MAGENTA, "teardown"); @@ -528,7 +533,10 @@ static void test_result(enum test_result result) break; } - g_idle_add(teardown_callback, test); + if (test->teardown_id > 0) + return; + + test->teardown_id = g_idle_add(teardown_callback, test); } void tester_test_passed(void) |