From 44e30afcdcb8df8bab18feb4f0e6720707d4a0e5 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 24 Jan 2014 21:28:42 -0800 Subject: [PATCH] shared: Avoid using GLib allocation functions for tester --- src/shared/tester.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/shared/tester.c b/src/shared/tester.c index 06fc4158a..eafbfb0f8 100644 --- a/src/shared/tester.c +++ b/src/shared/tester.c @@ -29,11 +29,13 @@ #include #include #include +#include #include #include #include +#include "src/shared/util.h" #include "src/shared/tester.h" #define COLOR_OFF "\x1B[0m" @@ -114,8 +116,8 @@ static void test_destroy(gpointer data) if (test->destroy) test->destroy(test->user_data); - g_free(test->name); - g_free(test); + free(test->name); + free(test); } void tester_print(const char *format, ...) @@ -190,9 +192,14 @@ void tester_add_full(const char *name, const void *test_data, return; } - test = g_new0(struct test_case, 1); + test = new0(struct test_case, 1); + if (!test) { + if (destroy) + destroy(user_data); + return; + } - test->name = g_strdup(name); + test->name = strdup(name); test->result = TEST_RESULT_NOT_RUN; test->stage = TEST_STAGE_INVALID; @@ -617,7 +624,7 @@ static gboolean wait_callback(gpointer user_data) wait->func(wait->user_data); - g_free(wait); + free(wait); return FALSE; } @@ -636,9 +643,9 @@ void tester_wait(unsigned int seconds, tester_wait_func_t func, test = test_current->data; - print_progress(test->name, COLOR_BLACK, "waiting %u seconds", seconds); - - wait = g_new0(struct wait_data, 1); + wait = new0(struct wait_data, 1); + if (!wait) + return; wait->seconds = seconds; wait->test = test; @@ -646,6 +653,8 @@ void tester_wait(unsigned int seconds, tester_wait_func_t func, wait->user_data = user_data; g_timeout_add(1000, wait_callback, wait); + + print_progress(test->name, COLOR_BLACK, "waiting %u seconds", seconds); } static gboolean signal_handler(GIOChannel *channel, GIOCondition condition, -- 2.47.3