diff --git a/SOURCES/0001-Use-atomic-reference-counting-for-GSource.patch b/SOURCES/0001-Use-atomic-reference-counting-for-GSource.patch
new file mode 100644
index 0000000..4ad90a5
--- /dev/null
+++ b/SOURCES/0001-Use-atomic-reference-counting-for-GSource.patch
@@ -0,0 +1,170 @@
+From 2bad3cb3bf8f0cc3f45057061f9a538ecf7742b6 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
+Date: Thu, 14 Feb 2019 17:46:33 +0200
+Subject: [PATCH 1/5] Use atomic reference counting for GSource
+
+If attached to a context already it would use a mutex instead but at
+least before that the reference counting is not thread-safe currently.
+---
+ glib/gmain.c | 50 +++++++++++++++-----------------------------------
+ 1 file changed, 15 insertions(+), 35 deletions(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index 26e68823d..5b91c3117 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -374,15 +374,6 @@ typedef struct _GSourceIter
+ #define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
+ #define SOURCE_BLOCKED(source) (((source)->flags & G_SOURCE_BLOCKED) != 0)
+ 
+-#define SOURCE_UNREF(source, context)                       \
+-   G_STMT_START {                                           \
+-    if ((source)->ref_count > 1)                            \
+-      (source)->ref_count--;                                \
+-    else                                                    \
+-      g_source_unref_internal ((source), (context), TRUE);  \
+-   } G_STMT_END
+-
+-
+ /* Forward declarations */
+ 
+ static void g_source_unref_internal             (GSource      *source,
+@@ -977,10 +968,10 @@ g_source_iter_next (GSourceIter *iter, GSource **source)
+    */
+ 
+   if (iter->source && iter->may_modify)
+-    SOURCE_UNREF (iter->source, iter->context);
++    g_source_unref_internal (iter->source, iter->context, TRUE);
+   iter->source = next_source;
+   if (iter->source && iter->may_modify)
+-    iter->source->ref_count++;
++    g_source_ref (iter->source);
+ 
+   *source = iter->source;
+   return *source != NULL;
+@@ -994,7 +985,7 @@ g_source_iter_clear (GSourceIter *iter)
+ {
+   if (iter->source && iter->may_modify)
+     {
+-      SOURCE_UNREF (iter->source, iter->context);
++      g_source_unref_internal (iter->source, iter->context, TRUE);
+       iter->source = NULL;
+     }
+ }
+@@ -1135,7 +1126,7 @@ g_source_attach_unlocked (GSource      *source,
+ 
+   source->context = context;
+   source->source_id = id;
+-  source->ref_count++;
++  g_source_ref (source);
+ 
+   g_hash_table_insert (context->sources, GUINT_TO_POINTER (id), source);
+ 
+@@ -1675,7 +1666,7 @@ g_source_set_funcs (GSource     *source,
+ {
+   g_return_if_fail (source != NULL);
+   g_return_if_fail (source->context == NULL);
+-  g_return_if_fail (source->ref_count > 0);
++  g_return_if_fail (g_atomic_int_get (&source->ref_count) > 0);
+   g_return_if_fail (funcs != NULL);
+ 
+   source->source_funcs = funcs;
+@@ -2050,19 +2041,9 @@ g_source_set_name_by_id (guint           tag,
+ GSource *
+ g_source_ref (GSource *source)
+ {
+-  GMainContext *context;
+-  
+   g_return_val_if_fail (source != NULL, NULL);
+ 
+-  context = source->context;
+-
+-  if (context)
+-    LOCK_CONTEXT (context);
+-
+-  source->ref_count++;
+-
+-  if (context)
+-    UNLOCK_CONTEXT (context);
++  g_atomic_int_inc (&source->ref_count);
+ 
+   return source;
+ }
+@@ -2078,12 +2059,11 @@ g_source_unref_internal (GSource      *source,
+   GSourceCallbackFuncs *old_cb_funcs = NULL;
+ 
+   g_return_if_fail (source != NULL);
+-  
++
+   if (!have_lock && context)
+     LOCK_CONTEXT (context);
+ 
+-  source->ref_count--;
+-  if (source->ref_count == 0)
++  if (g_atomic_int_dec_and_test (&source->ref_count))
+     {
+       TRACE (GLIB_SOURCE_BEFORE_FREE (source, context,
+                                       source->source_funcs->finalize));
+@@ -2107,20 +2087,20 @@ g_source_unref_internal (GSource      *source,
+ 	{
+           /* Temporarily increase the ref count again so that GSource methods
+            * can be called from finalize(). */
+-          source->ref_count++;
++          g_atomic_int_inc (&source->ref_count);
+ 	  if (context)
+ 	    UNLOCK_CONTEXT (context);
+ 	  source->source_funcs->finalize (source);
+ 	  if (context)
+ 	    LOCK_CONTEXT (context);
+-          source->ref_count--;
++          g_atomic_int_add (&source->ref_count, -1);
+ 	}
+ 
+       if (old_cb_funcs)
+         {
+           /* Temporarily increase the ref count again so that GSource methods
+            * can be called from callback_funcs.unref(). */
+-          source->ref_count++;
++          g_atomic_int_inc (&source->ref_count);
+           if (context)
+             UNLOCK_CONTEXT (context);
+ 
+@@ -2128,7 +2108,7 @@ g_source_unref_internal (GSource      *source,
+ 
+           if (context)
+             LOCK_CONTEXT (context);
+-          source->ref_count--;
++          g_atomic_int_add (&source->ref_count, -1);
+         }
+ 
+       g_free (source->name);
+@@ -3201,7 +3181,7 @@ g_main_dispatch (GMainContext *context)
+ 	    }
+ 	}
+       
+-      SOURCE_UNREF (source, context);
++      g_source_unref_internal (source, context, TRUE);
+     }
+ 
+   g_ptr_array_set_size (context->pending_dispatches, 0);
+@@ -3440,7 +3420,7 @@ g_main_context_prepare (GMainContext *context,
+   for (i = 0; i < context->pending_dispatches->len; i++)
+     {
+       if (context->pending_dispatches->pdata[i])
+-	SOURCE_UNREF ((GSource *)context->pending_dispatches->pdata[i], context);
++        g_source_unref_internal ((GSource *)context->pending_dispatches->pdata[i], context, TRUE);
+     }
+   g_ptr_array_set_size (context->pending_dispatches, 0);
+   
+@@ -3788,7 +3768,7 @@ g_main_context_check (GMainContext *context,
+ 
+       if (source->flags & G_SOURCE_READY)
+ 	{
+-	  source->ref_count++;
++          g_source_ref (source);
+ 	  g_ptr_array_add (context->pending_dispatches, source);
+ 
+ 	  n_ready++;
+-- 
+2.31.1
+
diff --git a/SOURCES/0001-gmain-g_main_context_check-can-skip-updating-polled-.patch b/SOURCES/0001-gmain-g_main_context_check-can-skip-updating-polled-.patch
new file mode 100644
index 0000000..cace858
--- /dev/null
+++ b/SOURCES/0001-gmain-g_main_context_check-can-skip-updating-polled-.patch
@@ -0,0 +1,204 @@
+From 4f0a31d66c2a6588495b8ae682f555584dafdf45 Mon Sep 17 00:00:00 2001
+From: Claudio Saavedra <csaavedra@igalia.com>
+Date: Wed, 21 Oct 2020 13:19:42 +0300
+Subject: [PATCH] gmain: g_main_context_check() can skip updating polled FD
+ sources
+
+If there is a file descriptor source that has a lower priority
+than the one for sources that are going to be dispatched,
+all subsequent file descriptor sources (internally sorted by
+file descriptor identifier) do not get an update in their GPollRec
+and later on wrong sources can be dispatched.
+
+Fix this by first finding the first GPollRec that matches the current
+GPollFD, instead of relying on it to be the current one. At
+the same time, document the assumptions about the ordering of the
+file descriptor records and array and make explicit in the documentation
+that the array needs to be passed to g_main_context_check() as it was
+received from g_main_context_query().
+
+Added a new test that reproduces the bug by creating two file
+descriptor sources and an idle one. Since the first
+file descriptor created has a lower identifier and a low priority,
+the second one is not dispatched even when it has the same, higher,
+priority as the idle source. After fixing this bug, both
+higher priority sources are dispatched as expected.
+
+While this patch was written independently, a similar fix for this
+bug was first submitted by Eugene M in GNOME/glib!562. Having a
+second fix that basically does the same is a reassurance that we
+are in the right here.
+
+Fixes #1592
+---
+ glib/gmain.c          | 32 ++++++++++++++++++++++--
+ glib/tests/mainloop.c | 57 +++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 87 insertions(+), 2 deletions(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index 95992253d..a59cd686c 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -3573,7 +3573,10 @@ g_main_context_prepare (GMainContext *context,
+  *       store #GPollFD records that need to be polled.
+  * @n_fds: (in): length of @fds.
+  *
+- * Determines information necessary to poll this main loop.
++ * Determines information necessary to poll this main loop. You should
++ * be careful to pass the resulting @fds array and its length @n_fds
++ * as is when calling g_main_context_check(), as this function relies
++ * on assumptions made when the array is filled.
+  *
+  * You must have successfully acquired the context with
+  * g_main_context_acquire() before you may call this function.
+@@ -3597,6 +3600,10 @@ g_main_context_query (GMainContext *context,
+ 
+   TRACE (GLIB_MAIN_CONTEXT_BEFORE_QUERY (context, max_priority));
+ 
++  /* fds is filled sequentially from poll_records. Since poll_records
++   * are incrementally sorted by file descriptor identifier, fds will
++   * also be incrementally sorted.
++   */
+   n_poll = 0;
+   lastpollrec = NULL;
+   for (pollrec = context->poll_records; pollrec; pollrec = pollrec->next)
+@@ -3611,6 +3618,10 @@ g_main_context_query (GMainContext *context,
+        */
+       events = pollrec->fd->events & ~(G_IO_ERR|G_IO_HUP|G_IO_NVAL);
+ 
++      /* This optimization --using the same GPollFD to poll for more
++       * than one poll record-- relies on the poll records being
++       * incrementally sorted.
++       */
+       if (lastpollrec && pollrec->fd->fd == lastpollrec->fd->fd)
+         {
+           if (n_poll - 1 < n_fds)
+@@ -3656,7 +3667,10 @@ g_main_context_query (GMainContext *context,
+  *       the last call to g_main_context_query()
+  * @n_fds: return value of g_main_context_query()
+  *
+- * Passes the results of polling back to the main loop.
++ * Passes the results of polling back to the main loop. You should be
++ * careful to pass @fds and its length @n_fds as received from
++ * g_main_context_query(), as this functions relies on assumptions
++ * on how @fds is filled.
+  *
+  * You must have successfully acquired the context with
+  * g_main_context_acquire() before you may call this function.
+@@ -3711,10 +3725,22 @@ g_main_context_check (GMainContext *context,
+       return FALSE;
+     }
+ 
++  /* The linear iteration below relies on the assumption that both
++   * poll records and the fds array are incrementally sorted by file
++   * descriptor identifier.
++   */
+   pollrec = context->poll_records;
+   i = 0;
+   while (pollrec && i < n_fds)
+     {
++      /* Make sure that fds is sorted by file descriptor identifier. */
++      g_assert (i <= 0 || fds[i - 1].fd < fds[i].fd);
++
++      /* Skip until finding the first GPollRec matching the current GPollFD. */
++      while (pollrec && pollrec->fd->fd != fds[i].fd)
++        pollrec = pollrec->next;
++
++      /* Update all consecutive GPollRecs that match. */
+       while (pollrec && pollrec->fd->fd == fds[i].fd)
+         {
+           if (pollrec->priority <= max_priority)
+@@ -3725,6 +3751,7 @@ g_main_context_check (GMainContext *context,
+           pollrec = pollrec->next;
+         }
+ 
++      /* Iterate to next GPollFD. */
+       i++;
+     }
+ 
+@@ -4320,6 +4347,7 @@ g_main_context_add_poll_unlocked (GMainContext *context,
+   newrec->fd = fd;
+   newrec->priority = priority;
+ 
++  /* Poll records are incrementally sorted by file descriptor identifier. */
+   prevrec = NULL;
+   nextrec = context->poll_records;
+   while (nextrec)
+diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c
+index f5d672a63..397921f2d 100644
+--- a/glib/tests/mainloop.c
++++ b/glib/tests/mainloop.c
+@@ -1511,6 +1511,62 @@ test_unix_file_poll (void)
+   close (fd);
+ }
+ 
++static void
++test_unix_fd_priority (void)
++{
++  gint fd1, fd2;
++  GMainLoop *loop;
++  GSource *source;
++
++  gint s1 = 0;
++  gboolean s2 = FALSE, s3 = FALSE;
++
++  g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/1592");
++
++  loop = g_main_loop_new (NULL, FALSE);
++
++  source = g_idle_source_new ();
++  g_source_set_callback (source, count_calls, &s1, NULL);
++  g_source_set_priority (source, 0);
++  g_source_attach (source, NULL);
++  g_source_unref (source);
++
++  fd1 = open ("/dev/random", O_RDONLY);
++  g_assert_cmpint (fd1, >=, 0);
++  source = g_unix_fd_source_new (fd1, G_IO_IN);
++  g_source_set_callback (source, (GSourceFunc) (void (*)(void)) (flag_bool), &s2, NULL);
++  g_source_set_priority (source, 10);
++  g_source_attach (source, NULL);
++  g_source_unref (source);
++
++  fd2 = open ("/dev/random", O_RDONLY);
++  g_assert_cmpint (fd2, >=, 0);
++  source = g_unix_fd_source_new (fd2, G_IO_IN);
++  g_source_set_callback (source, (GSourceFunc) (void (*)(void)) (flag_bool), &s3, NULL);
++  g_source_set_priority (source, 0);
++  g_source_attach (source, NULL);
++  g_source_unref (source);
++
++  /* This tests a bug that depends on the source with the lowest FD
++     identifier to have the lowest priority. Make sure that this is
++     the case. */
++  g_assert_cmpint (fd1, <, fd2);
++
++  g_assert_true (g_main_context_iteration (NULL, FALSE));
++
++  /* Idle source should have been dispatched. */
++  g_assert_cmpint (s1, ==, 1);
++  /* Low priority FD source shouldn't have been dispatched. */
++  g_assert_false (s2);
++  /* Default priority FD source should have been dispatched. */
++  g_assert_true (s3);
++
++  g_main_loop_unref (loop);
++
++  close (fd1);
++  close (fd2);
++}
++
+ #endif
+ 
+ static gboolean
+@@ -1751,6 +1807,7 @@ main (int argc, char *argv[])
+   g_test_add_func ("/mainloop/source-unix-fd-api", test_source_unix_fd_api);
+   g_test_add_func ("/mainloop/wait", test_mainloop_wait);
+   g_test_add_func ("/mainloop/unix-file-poll", test_unix_file_poll);
++  g_test_add_func ("/mainloop/unix-fd-priority", test_unix_fd_priority);
+ #endif
+   g_test_add_func ("/mainloop/nfds", test_nfds);
+ 
+-- 
+2.31.1
+
diff --git a/SOURCES/0002-GMainContext-Fix-GSource-iterator-if-iteration-can-m.patch b/SOURCES/0002-GMainContext-Fix-GSource-iterator-if-iteration-can-m.patch
new file mode 100644
index 0000000..b5c4191
--- /dev/null
+++ b/SOURCES/0002-GMainContext-Fix-GSource-iterator-if-iteration-can-m.patch
@@ -0,0 +1,43 @@
+From 323d0c7658a9a44efc327840c0667044a4b98f89 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
+Date: Mon, 3 Feb 2020 15:38:28 +0200
+Subject: [PATCH 2/5] GMainContext - Fix GSource iterator if iteration can
+ modify the list
+
+We first have to ref the next source and then unref the previous one.
+This might be the last reference to the previous source, and freeing the
+previous source might unref and free the next one which would then leave
+use with a dangling pointer here.
+
+Fixes https://gitlab.gnome.org/GNOME/glib/issues/2031
+---
+ glib/gmain.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index 5b91c3117..a3ea1d36c 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -965,13 +965,17 @@ g_source_iter_next (GSourceIter *iter, GSource **source)
+    * GSourceList to be removed from source_lists (if iter->source is
+    * the only source in its list, and it is destroyed), so we have to
+    * keep it reffed until after we advance iter->current_list, above.
++   *
++   * Also we first have to ref the next source before unreffing the
++   * previous one as unreffing the previous source can potentially
++   * free the next one.
+    */
++  if (next_source && iter->may_modify)
++    g_source_ref (next_source);
+ 
+   if (iter->source && iter->may_modify)
+     g_source_unref_internal (iter->source, iter->context, TRUE);
+   iter->source = next_source;
+-  if (iter->source && iter->may_modify)
+-    g_source_ref (iter->source);
+ 
+   *source = iter->source;
+   return *source != NULL;
+-- 
+2.31.1
+
diff --git a/SOURCES/0003-GMainContext-Fix-memory-leaks-and-memory-corruption-.patch b/SOURCES/0003-GMainContext-Fix-memory-leaks-and-memory-corruption-.patch
new file mode 100644
index 0000000..e02888e
--- /dev/null
+++ b/SOURCES/0003-GMainContext-Fix-memory-leaks-and-memory-corruption-.patch
@@ -0,0 +1,109 @@
+From fc051ec83d8894dd754bf364562ba9be9ff999fc Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
+Date: Mon, 3 Feb 2020 15:35:51 +0200
+Subject: [PATCH 3/5] GMainContext - Fix memory leaks and memory corruption
+ when freeing sources while freeing a context
+
+Instead of destroying sources directly while freeing the context, and
+potentially freeing them if this was the last reference to them, collect
+new references of all sources in a separate list before and at the same
+time invalidate their context so that they can't access it anymore. Only
+once all sources have their context invalidated, destroy them while
+still keeping a reference to them. Once all sources are destroyed we get
+rid of the additional references and free them if nothing else keeps a
+reference to them anymore.
+
+This fixes a regression introduced by 26056558be in 2012.
+
+The previous code that invalidated the context of each source and then
+destroyed it before going to the next source without keeping an
+additional reference caused memory leaks or memory corruption depending
+on the order of the sources in the sources lists.
+
+If a source was destroyed it might happen that this was the last
+reference to this source, and it would then be freed. This would cause
+the finalize function to be called, which might destroy and unref
+another source and potentially free it. This other source would then
+either
+- go through the normal free logic and change the intern linked list
+  between the sources, while other sources that are unreffed as part of
+  the main context freeing would not. As such the list would be in an
+  inconsistent state and we might dereference freed memory.
+- go through the normal destroy and free logic but because the context
+  pointer was already invalidated it would simply mark the source as
+  destroyed without actually removing it from the context. This would
+  then cause a memory leak because the reference owned by the context is
+  not freed.
+
+Fixes https://github.com/gtk-rs/glib/issues/583 while still keeping
+https://bugzilla.gnome.org/show_bug.cgi?id=661767 fixes.
+---
+ glib/gmain.c | 35 ++++++++++++++++++++++++++++++++++-
+ 1 file changed, 34 insertions(+), 1 deletion(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index a3ea1d36c..1c249ad02 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -534,6 +534,7 @@ g_main_context_unref (GMainContext *context)
+   GSourceIter iter;
+   GSource *source;
+   GList *sl_iter;
++  GSList *s_iter, *remaining_sources = NULL;
+   GSourceList *list;
+   guint i;
+ 
+@@ -553,10 +554,30 @@ g_main_context_unref (GMainContext *context)
+ 
+   /* g_source_iter_next() assumes the context is locked. */
+   LOCK_CONTEXT (context);
+-  g_source_iter_init (&iter, context, TRUE);
++
++  /* First collect all remaining sources from the sources lists and store a
++   * new reference in a separate list. Also set the context of the sources
++   * to NULL so that they can't access a partially destroyed context anymore.
++   *
++   * We have to do this first so that we have a strong reference to all
++   * sources and destroying them below does not also free them, and so that
++   * none of the sources can access the context from their finalize/dispose
++   * functions. */
++  g_source_iter_init (&iter, context, FALSE);
+   while (g_source_iter_next (&iter, &source))
+     {
+       source->context = NULL;
++      remaining_sources = g_slist_prepend (remaining_sources, g_source_ref (source));
++    }
++  g_source_iter_clear (&iter);
++
++  /* Next destroy all sources. As we still hold a reference to all of them,
++   * this won't cause any of them to be freed yet and especially prevents any
++   * source that unrefs another source from its finalize function to be freed.
++   */
++  for (s_iter = remaining_sources; s_iter; s_iter = s_iter->next)
++    {
++      source = s_iter->data;
+       g_source_destroy_internal (source, context, TRUE);
+     }
+   UNLOCK_CONTEXT (context);
+@@ -581,6 +602,18 @@ g_main_context_unref (GMainContext *context)
+   g_cond_clear (&context->cond);
+ 
+   g_free (context);
++
++  /* And now finally get rid of our references to the sources. This will cause
++   * them to be freed unless something else still has a reference to them. Due
++   * to setting the context pointers in the sources to NULL above, this won't
++   * ever access the context or the internal linked list inside the GSource.
++   * We already removed the sources completely from the context above. */
++  for (s_iter = remaining_sources; s_iter; s_iter = s_iter->next)
++    {
++      source = s_iter->data;
++      g_source_unref_internal (source, NULL, FALSE);
++    }
++  g_slist_free (remaining_sources);
+ }
+ 
+ /* Helper function used by mainloop/overflow test.
+-- 
+2.31.1
+
diff --git a/SOURCES/0004-GMainContext-Move-mutex-unlocking-in-destructor-righ.patch b/SOURCES/0004-GMainContext-Move-mutex-unlocking-in-destructor-righ.patch
new file mode 100644
index 0000000..068f317
--- /dev/null
+++ b/SOURCES/0004-GMainContext-Move-mutex-unlocking-in-destructor-righ.patch
@@ -0,0 +1,36 @@
+From 1d16e92028f235ed9cd786070832d5bd71017661 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
+Date: Tue, 11 Feb 2020 09:34:38 +0200
+Subject: [PATCH 4/5] GMainContext - Move mutex unlocking in destructor right
+ before freeing the mutex
+
+This does not have any behaviour changes but is cleaner. The mutex is
+only unlocked now after all operations on the context are done and right
+before freeing the mutex and the context itself.
+---
+ glib/gmain.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index 1c249ad02..44e6ed0c3 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -580,7 +580,6 @@ g_main_context_unref (GMainContext *context)
+       source = s_iter->data;
+       g_source_destroy_internal (source, context, TRUE);
+     }
+-  UNLOCK_CONTEXT (context);
+ 
+   for (sl_iter = context->source_lists; sl_iter; sl_iter = sl_iter->next)
+     {
+@@ -591,6 +590,7 @@ g_main_context_unref (GMainContext *context)
+ 
+   g_hash_table_destroy (context->sources);
+ 
++  UNLOCK_CONTEXT (context);
+   g_mutex_clear (&context->mutex);
+ 
+   g_ptr_array_free (context->pending_dispatches, TRUE);
+-- 
+2.31.1
+
diff --git a/SOURCES/0005-gmain-Fix-possible-locking-issue-in-source-unref.patch b/SOURCES/0005-gmain-Fix-possible-locking-issue-in-source-unref.patch
new file mode 100644
index 0000000..5851f29
--- /dev/null
+++ b/SOURCES/0005-gmain-Fix-possible-locking-issue-in-source-unref.patch
@@ -0,0 +1,29 @@
+From 02ad7294ad5895178df73a6cd8546c6e67097493 Mon Sep 17 00:00:00 2001
+From: Benjamin Berg <bberg@redhat.com>
+Date: Tue, 13 Oct 2020 15:09:43 +0200
+Subject: [PATCH 5/5] gmain: Fix possible locking issue in source unref
+
+When unref'ing child sources, the lock is already held. But instead of
+passing TRUE to g_source_unref_internal it currently passes whether the
+lock was already held outside of the current invocation. Just pass TRUE
+to fix this possible issue.
+---
+ glib/gmain.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/glib/gmain.c b/glib/gmain.c
+index 44e6ed0c3..95992253d 100644
+--- a/glib/gmain.c
++++ b/glib/gmain.c
+@@ -2164,7 +2164,7 @@ g_source_unref_internal (GSource      *source,
+             g_slist_remove (source->priv->child_sources, child_source);
+           child_source->priv->parent_source = NULL;
+ 
+-          g_source_unref_internal (child_source, context, have_lock);
++          g_source_unref_internal (child_source, context, TRUE);
+         }
+ 
+       g_slice_free (GSourcePrivate, source->priv);
+-- 
+2.31.1
+
diff --git a/SPECS/glib2.spec b/SPECS/glib2.spec
index 871cf04..299a1d3 100644
--- a/SPECS/glib2.spec
+++ b/SPECS/glib2.spec
@@ -5,7 +5,7 @@
 
 Name: glib2
 Version: 2.56.4
-Release: 11%{?dist}
+Release: 12%{?dist}
 Summary: A library of handy utility functions
 
 License: LGPLv2+
@@ -95,6 +95,16 @@ Patch102: 0003-glocalfileoutputstream-Add-a-missing-O_CLOEXEC-flag-.patch
 # https://bugzilla.redhat.com/show_bug.cgi?id=1938284
 Patch110: 0001-libcharset-Drop-a-redundant-environment-variable.patch
 
+# https://bugzilla.redhat.com/show_bug.cgi?id=1948988
+Patch120: 0001-Use-atomic-reference-counting-for-GSource.patch
+Patch121: 0002-GMainContext-Fix-GSource-iterator-if-iteration-can-m.patch
+Patch122: 0003-GMainContext-Fix-memory-leaks-and-memory-corruption-.patch
+Patch123: 0004-GMainContext-Move-mutex-unlocking-in-destructor-righ.patch
+Patch124: 0005-gmain-Fix-possible-locking-issue-in-source-unref.patch
+
+# https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1713
+Patch130: 0001-gmain-g_main_context_check-can-skip-updating-polled-.patch
+
 %description
 GLib is the low-level core library that forms the basis for projects
 such as GTK+ and GNOME. It provides data structure handling for C,
@@ -292,6 +302,10 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
 %{_datadir}/installed-tests
 
 %changelog
+* Wed May 05 2021 Michael Catanzaro <mcatanzaro@redhat.com> - 2.56.4-12
+- Fix various problems in GMainContext
+  Resolves: #1948988
+
 * Tue May 04 2021 Michael Catanzaro <mcatanzaro@redhat.com> - 2.56.4-11
 - Remove CHARSETALIASDIR environment variable
   Resolves: #1938284