diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c index f640c005b..4d971e8d2 100644 --- a/glib/gthread-posix.c +++ b/glib/gthread-posix.c @@ -1111,8 +1111,9 @@ g_system_thread_new (GThreadFunc thread_func, if (ret == EAGAIN) { g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN, - "Error creating thread: %s", g_strerror (ret)); - return thread; + "Error creating thread: %s", g_strerror (ret)); + g_slice_free (GRealThread, thread); + return NULL; } posix_check_err (ret, "pthread_create"); diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c index e380b84d8..2babc9242 100644 --- a/glib/gthread-win32.c +++ b/glib/gthread-win32.c @@ -518,7 +518,8 @@ g_system_thread_new (GThreadFunc func, "Error creating thread: %s", win_error); g_free (retval); g_free (win_error); - return thread; + g_slice_free (GRealThread, thread); + return NULL; } *(GThreadData **) &(thread->system_thread) = retval; diff --git a/glib/gthread.c b/glib/gthread.c index e259bad9e..7896df8ff 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -799,27 +799,22 @@ g_thread_new_internal (const gchar *name, gsize stack_size, GError **error) { - GRealThread *result; - GError *local_error = NULL; + GRealThread *thread; g_return_val_if_fail (func != NULL, NULL); G_LOCK (g_thread_new); - result = g_system_thread_new (proxy, stack_size, joinable, &local_error); - result->thread.joinable = joinable; - result->thread.func = func; - result->thread.data = data; - result->name = name; + thread = g_system_thread_new (proxy, stack_size, joinable, error); + if (thread) + { + thread->thread.joinable = joinable; + thread->thread.func = func; + thread->thread.data = data; + thread->name = name; + } G_UNLOCK (g_thread_new); - if (local_error) - { - g_propagate_error (error, local_error); - g_system_thread_free (result); - return NULL; - } - - return (GThread*) result; + return (GThread*) thread; } /**