From 96766ac51c5ecd2c777b24f2341b62ccba0ad522 Mon Sep 17 00:00:00 2001 From: Peter Bloomfield Date: Mon, 21 Jul 2025 18:48:35 -0400 Subject: [PATCH] gthreadpool: Clean up when g_thread_pool_new fails --- glib/gthreadpool.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c index e511102c3..8441b9d1f 100644 --- a/glib/gthreadpool.c +++ b/glib/gthreadpool.c @@ -631,6 +631,18 @@ g_thread_pool_new_full (GFunc func, spawn_thread_queue = g_async_queue_new (); g_cond_init (&spawn_thread_cond); pool_spawner = g_thread_try_new ("pool-spawner", g_thread_pool_spawn_thread, NULL, &local_error); + if (pool_spawner == NULL) + { + /* The only way to know that the pool_spawner exists is + * if (spawn_thread_queue != NULL), so if creating the pool_spawner + * failed, we must destroy the queue. + */ + g_clear_pointer (&spawn_thread_queue, g_async_queue_unref); + /* We must also clear spawn_thread_cond, so that a future attempt + * to create a non-exclusive pool can safely initialize it. + */ + g_cond_clear (&spawn_thread_cond); + } g_ignore_leak (pool_spawner); } G_UNLOCK (init);