[bockbuild] Moved Gtk+ files back to main bockbuild repo
[mono.git] / bockbuild / mac-sdk / patches / glib-recursive-poll.patch
1 From 5dfd206b09f91cba45fa8e2b66e1b57aafe30868 Mon Sep 17 00:00:00 2001
2 From: Kristian Rietveld <kris@lanedo.com>
3 Date: Mon, 8 Jul 2013 12:02:00 +0200
4 Subject: [PATCH] Make g_main_context_iterate resilient to recursion in poll
5
6 On OS X, main loop recursion may happen during the call the poll.
7 As a result, the allocated poll array may be re-allocated (note that
8 it is always enlarged, never shrunk). By always using cached_poll_array
9 after the poll function, reads from bad memory are avoided.
10 ---
11  glib/gmain.c |   28 +++++++++++++++-------------
12  1 file changed, 15 insertions(+), 13 deletions(-)
13
14 diff --git a/glib/gmain.c b/glib/gmain.c
15 index 077a935..529f2b6 100644
16 --- a/glib/gmain.c
17 +++ b/glib/gmain.c
18 @@ -3065,8 +3065,7 @@ g_main_context_iterate (GMainContext *context,
19    gint max_priority;
20    gint timeout;
21    gboolean some_ready;
22 -  gint nfds, allocated_nfds;
23 -  GPollFD *fds = NULL;
24 +  gint nfds;
25
26    UNLOCK_CONTEXT (context);
27
28 @@ -3095,29 +3094,32 @@ g_main_context_iterate (GMainContext *context,
29        context->cached_poll_array = g_new (GPollFD, context->n_poll_records);
30      }
31
32 -  allocated_nfds = context->cached_poll_array_size;
33 -  fds = context->cached_poll_array;
34 -
35    UNLOCK_CONTEXT (context);
36
37    g_main_context_prepare (context, &max_priority);
38
39 -  while ((nfds = g_main_context_query (context, max_priority, &timeout, fds,
40 -                                      allocated_nfds)) > allocated_nfds)
41 +  while ((nfds = g_main_context_query (context, max_priority, &timeout,
42 +                                       context->cached_poll_array,
43 +                                       context->cached_poll_array_size))
44 +         > context->cached_poll_array_size)
45      {
46        LOCK_CONTEXT (context);
47 -      g_free (fds);
48 -      context->cached_poll_array_size = allocated_nfds = nfds;
49 -      context->cached_poll_array = fds = g_new (GPollFD, nfds);
50 +      g_free (context->cached_poll_array);
51 +      context->cached_poll_array_size = nfds;
52 +      context->cached_poll_array = g_new (GPollFD, nfds);
53        UNLOCK_CONTEXT (context);
54      }
55
56    if (!block)
57      timeout = 0;
58
59 -  g_main_context_poll (context, timeout, max_priority, fds, nfds);
60 -
61 -  some_ready = g_main_context_check (context, max_priority, fds, nfds);
62 +  g_main_context_poll (context, timeout, max_priority,
63 +                       context->cached_poll_array,
64 +                       nfds);
65 +
66 +  some_ready = g_main_context_check (context, max_priority,
67 +                                     context->cached_poll_array,
68 +                                     nfds);
69
70    if (dispatch)
71      g_main_context_dispatch (context);
72 --
73 1.7.10