After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 364868 - GDI resource leak in GtkStatusIcon on win32
GDI resource leak in GtkStatusIcon on win32
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Win32
2.10.x
Other Windows
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2006-10-25 02:17 UTC by Hiroyuki Yamamoto
Modified: 2008-01-20 17:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkStatusIcon resource leak fix (revised) (2.66 KB, patch)
2006-11-02 06:15 UTC, Hiroyuki Yamamoto
none Details | Review

Description Hiroyuki Yamamoto 2006-10-25 02:17:13 UTC
GtkStatusIcon leaks GDI objects when icon image is updated on Windows. If you enable blinking with gtk_status_icon_set_blinking(), the usage of GDI objects keeps increasing.

In gtkstatusicon.c::gtk_status_icon_update_image(), priv->nid.hIcon is updated to the new one, but the old one is not deleted. When gdk_win32_pixbuf_to_hicon_libgtk_only() is called, the new icon is created by CreateIconIndirect(), and it must be deleted with DestroyIcon() afterward.

The following patch fixes the leaks.

--- gtkstatusicon.c.orig        Sun Sep 10 15:33:16 2006
+++ gtkstatusicon.c     Wed Oct 25 10:59:35 2006
@@ -791,6 +791,8 @@
                                 gtk_status_icon_blank_icon (status_icon));
 #endif
 #ifdef GDK_WINDOWING_WIN32
+      if (priv->nid.hIcon)
+        DestroyIcon (priv->nid.hIcon);
       priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (gtk_status_icon_blank_icon (status_icon));
       priv->nid.uFlags |= NIF_ICON;
       if (priv->nid.hWnd != NULL && priv->visible)
@@ -832,6 +834,8 @@
            gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled);
 #endif
 #ifdef GDK_WINDOWING_WIN32
+           if (priv->nid.hIcon)
+             DestroyIcon (priv->nid.hIcon);
            priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (scaled);
            priv->nid.uFlags |= NIF_ICON;
            if (priv->nid.hWnd != NULL && priv->visible)
@@ -870,6 +874,8 @@
                                    priv->image_data.stock_id,
                                    GTK_ICON_SIZE_SMALL_TOOLBAR,
                                    NULL);
+         if (priv->nid.hIcon)
+           DestroyIcon (priv->nid.hIcon);
          priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
          priv->nid.uFlags |= NIF_ICON;
          if (priv->nid.hWnd != NULL && priv->visible)
@@ -897,6 +903,8 @@
                                      priv->size,
                                      0, NULL);
          
+         if (priv->nid.hIcon)
+           DestroyIcon (priv->nid.hIcon);
          priv->nid.hIcon = gdk_win32_pixbuf_to_hicon_libgtk_only (pixbuf);
          priv->nid.uFlags |= NIF_ICON;
          if (priv->nid.hWnd != NULL && priv->visible)
Comment 1 Hiroyuki Yamamoto 2006-10-25 02:41:07 UTC
Maybe priv->nid.hIcon must also be freed in gtk_status_icon_finalize() after Shell_NotifyIconW (NIM_DELETE, &priv->nid).
Comment 2 Tor Lillqvist 2006-10-29 00:30:34 UTC
Does Shell_NotifyIcon() make a copy of the icon passed to it? If no, isn't it then wrong to call DestroyIcon on the icon that might still be in use?
Comment 3 Hiroyuki Yamamoto 2006-10-30 02:23:15 UTC
Shell_NotifyIcon() doesn't make a copy of the icon passed to it.
The patch was a quick hack, so it's better to copy the old hIcon to the temporary variable and destroy it after Shell_NotifyIcon().
Comment 4 Hiroyuki Yamamoto 2006-11-02 06:15:16 UTC
Created attachment 75817 [details] [review]
GtkStatusIcon resource leak fix (revised)

DestroyIcon() is called after Shell_NotifyIcon() now.
I've also added DestroyIcon() in gtk_status_icon_finalize().
Comment 5 Tor Lillqvist 2006-12-28 16:55:47 UTC
Patch applied to HEAD and gtk-2-10, thanks.

2006-12-28  Tor Lillqvist  <tml@novell.com>

	* gtk/gtkstatusicon.c (gtk_status_icon_finalize)
	(gtk_status_icon_update_image): Don't leak HICONs on
	Win32. (#364868, Hiroyuki Yamamoto)
Comment 6 Paul Pogonyshev 2008-01-20 17:04:56 UTC
Can anyone have a look at bug 510278 and test if it is still present with GTK+ 2.12?