summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@endlessos.org>2023-03-06 15:44:26 +0000
committerPhilip Withnall <pwithnall@endlessos.org>2023-04-24 13:02:36 +0100
commit3926af723a7469a2ea492307f421820361d617b3 (patch)
tree4924f28a82b66a3ad93a50815fad4dfb816cc95a
parent44616ebafdca578e0c9ad7a345b2c286c89040c5 (diff)
downloadglib-3926af723a7469a2ea492307f421820361d617b3.tar.gz
gmain: Add precondition assertions to g_main_context_release()
As with the previous commit. The logic has to be a little contorted here to avoid leaving the context locked after emitting the critical warning. Execution does (and should) continue after a critical warning by default, so we should do our best to recover. Inspired by https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3302. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
-rw-r--r--glib/gmain.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/glib/gmain.c b/glib/gmain.c
index d34648f51..191e77345 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3592,9 +3592,23 @@ g_main_context_release (GMainContext *context)
{
if (context == NULL)
context = g_main_context_default ();
-
+
LOCK_CONTEXT (context);
+#ifndef G_DISABLE_CHECKS
+ if (G_UNLIKELY (context->owner != G_THREAD_SELF || context->owner_count == 0))
+ {
+ GThread *context_owner = context->owner;
+ guint context_owner_count = context->owner_count;
+
+ UNLOCK_CONTEXT (context);
+
+ g_critical ("g_main_context_release() called on a context (%p, owner %p, "
+ "owner count %u) which is not acquired by the current thread",
+ context, context_owner, context_owner_count);
+ }
+#endif /* !G_DISABLE_CHECKS */
+
g_main_context_release_unlocked (context);
UNLOCK_CONTEXT (context);