summaryrefslogtreecommitdiff
path: root/gdk/quartz
diff options
context:
space:
mode:
authorJohn Ralls <jralls@ceridwen.us>2011-01-02 10:23:20 -0800
committerJohn Ralls <jralls@ceridwen.us>2011-01-02 10:23:20 -0800
commitacf13456b16cef464ed01c3b36dfad2f5ecb5468 (patch)
treee0da62eb4a35020829e15e5b32631363893fe7fa /gdk/quartz
parent23506c0e44e9ebe84a2155aa62b0dd0122685c95 (diff)
downloadgtk+-acf13456b16cef464ed01c3b36dfad2f5ecb5468.tar.gz
Fix refresh of static autorelease_pool so that it doesn't happen in gtk-nested loops.
Diffstat (limited to 'gdk/quartz')
-rw-r--r--gdk/quartz/gdkeventloop-quartz.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/gdk/quartz/gdkeventloop-quartz.c b/gdk/quartz/gdkeventloop-quartz.c
index a2a2cd3153..39f5c0aee3 100644
--- a/gdk/quartz/gdkeventloop-quartz.c
+++ b/gdk/quartz/gdkeventloop-quartz.c
@@ -632,21 +632,20 @@ gdk_event_check (GSource *source)
GDK_THREADS_ENTER ();
- /* XXX: This check isn't right it won't handle a recursive GLib main
- * loop run within an outer CFRunLoop run. Such loops will pile up
- * memory. Fixing this requires setting a flag *only* when we call
- * g_main_context_check() from within the run loop iteraton code,
- * and also maintaining our own stack of run loops... allocating and
- * releasing NSAutoReleasePools not properly nested with CFRunLoop
- * runs seems to cause problems.
- */
- if (current_loop_level == 0)
+/* Refresh the autorelease pool if we're at the base CFRunLoop level
+ * (indicated by current_loop_level) and the base g_main_loop level
+ * (indicated by g_main_depth()). Messing with the autorelease pool at
+ * any level of nesting can cause access to deallocated memory because
+ * autorelease_pool is static and releasing a pool will cause all
+ * pools allocated inside of it to be released as well.
+ */
+ if (current_loop_level == 0 && g_main_depth() == 0)
{
if (autorelease_pool)
[autorelease_pool release];
autorelease_pool = [[NSAutoreleasePool alloc] init];
}
-
+
retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
_gdk_quartz_event_loop_check_pending ());