Q:

GDI object leak on refocus in cairo or gtk on windows?

I have a program (gummi) that uses cairo, poppler, and gtk+.  Every time I switch focus with alt-tab (but not so much when I change focus using other means), task manager tells me that it gains 10-20 GDI objects.   GDIView tells me that these are mostly bitmap and DCs, though these only account for most of the "GDI Total"; there are 3-4 times as many "All GDI" as there are "GDI Total".
How do I go about figuring out if this is a bug in gummi (I think it's unlikely, since I don't think gummi does anything on refocus/redraw), cairo, poppler, or gtk?  How do I go about finding where the bug is so I can submit a bug report?  (Alternatively, if this is a known bug with gtk/cairo/poppler, can someone point me at a bug report?)
As mentioned on other threads ( Win32Exception: Operation completed successfully ), windows limits a process to 10,000 handles, and I've had gummi segfault, presumably from reaching this limit.  The gdb backtrace from such an event is copied below.
(gummi.exe:14008): Gdk-WARNING **: gdkgc-win32.c:830: SaveDC failed: The operation completed successfully.

(gummi.exe:14008): Gdk-WARNING **: gdkgc-win32.c:970: RestoreDC failed: The operation completed successfully.
pnc=: T
Program received signal SIGSEGV, Segmentation fault.
0x68de05bd in cairo_image_surface_get_data ()
   from d:\opt\gtk\bin\libcairo-2.dll
(gdb) bt
#0  0x68de05bd in cairo_image_surface_get_data ()
   from d:\opt\gtk\bin\libcairo-2.dll
#1  0x6c38d268 in _gdk_pixmap_new ()
   from d:\opt\gtk\bin\libgdk-win32-2.0-0.dll
#2  0x62d453a5 in draw_extension ()
   from d:\opt\gtk\lib\gtk-2.0\2.10.0\engines\libwimp.dll
#3  0x0155fdb6 in gtk_notebook_draw_tab ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#4  0x015601d7 in gtk_notebook_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#5  0x0153b916 in _gtk_marshal_BOOLEAN__BOXED ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#6  0x63a451f9 in g_closure_invoke ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#7  0x63a54512 in signal_emit_unlocked_R ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#8  0x63a5b614 in g_signal_emit_valist ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#9  0x63a5b962 in g_signal_emit ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#10 0x0165b557 in gtk_widget_event_internal ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#11 0x014b6b0d in gtk_container_propagate_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#12 0x014b6b48 in gtk_container_expose_child ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#13 0x0147c026 in gtk_box_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#14 0x014b5436 in gtk_container_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#15 0x014b5611 in gtk_container_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#16 0x0153b916 in _gtk_marshal_BOOLEAN__BOXED ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#17 0x63a451f9 in g_closure_invoke ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#18 0x63a54512 in signal_emit_unlocked_R ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#19 0x63a5b614 in g_signal_emit_valist ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#20 0x63a5b962 in g_signal_emit ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#21 0x0165b557 in gtk_widget_event_internal ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#22 0x014b6b0d in gtk_container_propagate_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#23 0x014b6b48 in gtk_container_expose_child ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#24 0x0156a555 in gtk_paned_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#25 0x014b5436 in gtk_container_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#26 0x014b5611 in gtk_container_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#27 0x0156a894 in gtk_paned_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#28 0x0153b916 in _gtk_marshal_BOOLEAN__BOXED ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#29 0x63a451f9 in g_closure_invoke ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#30 0x63a54512 in signal_emit_unlocked_R ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#31 0x63a5b614 in g_signal_emit_valist ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#32 0x63a5b962 in g_signal_emit ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#33 0x0165b557 in gtk_widget_event_internal ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#34 0x014b6b0d in gtk_container_propagate_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#35 0x014b6b48 in gtk_container_expose_child ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#36 0x0147c026 in gtk_box_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#37 0x014b5436 in gtk_container_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#38 0x014b5611 in gtk_container_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#39 0x0153b916 in _gtk_marshal_BOOLEAN__BOXED ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#40 0x63a451f9 in g_closure_invoke ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#41 0x63a54512 in signal_emit_unlocked_R ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#42 0x63a5b614 in g_signal_emit_valist ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#43 0x63a5b962 in g_signal_emit ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#44 0x0165b557 in gtk_widget_event_internal ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#45 0x014b6b0d in gtk_container_propagate_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#46 0x014b6b48 in gtk_container_expose_child ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#47 0x014b5436 in gtk_container_forall ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#48 0x014b5611 in gtk_container_expose ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#49 0x0153b916 in _gtk_marshal_BOOLEAN__BOXED ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#50 0x63a452c2 in g_closure_invoke ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#51 0x63a54512 in signal_emit_unlocked_R ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#52 0x63a5b614 in g_signal_emit_valist ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#53 0x63a5b962 in g_signal_emit ()
   from d:\opt\gtk\bin\libgobject-2.0-0.dll
#54 0x0165b557 in gtk_widget_event_internal ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#55 0x0153a22f in gtk_main_do_event ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#56 0x6c3641dd in _gdk_window_process_updates_recurse ()
   from d:\opt\gtk\bin\libgdk-win32-2.0-0.dll
#57 0x6c35f6b6 in gdk_window_process_updates_internal ()
   from d:\opt\gtk\bin\libgdk-win32-2.0-0.dll
#58 0x6c361497 in gdk_window_process_all_updates ()
   from d:\opt\gtk\bin\libgdk-win32-2.0-0.dll
#59 0x6c361507 in gdk_window_update_idle ()
   from d:\opt\gtk\bin\libgdk-win32-2.0-0.dll
#60 0x6c34137c in gdk_threads_dispatch ()
   from d:\opt\gtk\bin\libgdk-win32-2.0-0.dll
#61 0x685eb167 in g_main_context_dispatch ()
   from d:\opt\gtk\bin\libglib-2.0-0.dll
#62 0x685eb90d in g_main_context_iterate.clone.5 ()
   from d:\opt\gtk\bin\libglib-2.0-0.dll
#63 0x685ebd9d in g_main_loop_run ()
   from d:\opt\gtk\bin\libglib-2.0-0.dll
#64 0x01539038 in gtk_main ()
   from d:\opt\gtk\bin\libgtk-win32-2.0-0.dll
#65 0x0040950e in gui_main (builder=0x33f5090) at gui/gui-main.c:281
#66 0x00428378 in main (argc=1, argv=0x3f56c8) at main.c:157
(gdb)

I'm using cairo and gtk+ from gtk+-bundle_2.24.10-20120208_win32 from the 32-bit download at http://www.gtk.org/download/win32.php, http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip.  This project also uses gtksourceview-2.10.0, libpng-1.5.10, openjpeg-1.5.0, poppler-0.18.4, and some other libraries, ~all built from source under MinGW, that I don't think are relevant to graphics.

A:

This kind of problem wouldn't have been unnoticed from the GTK team, this is most probably a gummi bug. Check the expose-event signal handler for that program, and make sure it doesn't allocate stuff without freeing them.
GDI leaks are indeed, tricky (had problems in MFC with that, and the problem was the app).
UPDATE:
Seems I was wrong, it's GTK bug 671538.
You may also find some advice on this thread.

