public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
From: Jon TURNEY <jon.turney@dronecode.org.uk>
To: cygwin-xfree@cygwin.com
Cc: Jon TURNEY <jon.turney@dronecode.org.uk>
Subject: [PATCH] Cygwin/X: Fix a GDI bitmap resource leak of window icons
Date: Thu, 22 Jul 2010 20:35:00 -0000	[thread overview]
Message-ID: <1279830920-5748-1-git-send-email-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <4C48AB39.7050703@dronecode.org.uk>

Ensure any icon created specially for a window is destroyed when
the window is destroyed

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 hw/xwin/winmultiwindowicons.c  |    3 ++-
 hw/xwin/winmultiwindowwindow.c |   13 ++++++++++++-
 hw/xwin/winwin32rootless.c     |   20 ++++++++++----------
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c
index cb27d2f..86ad51e 100644
--- a/hw/xwin/winmultiwindowicons.c
+++ b/hw/xwin/winmultiwindowicons.c
@@ -631,6 +631,7 @@ void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon)
     *pIcon = hIcon;
   else
     winDestroyIcon(hIcon);
+
   if (pSmallIcon)
     *pSmallIcon = hSmallIcon;
   else
@@ -639,7 +640,7 @@ void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon)
 
 void winDestroyIcon(HICON hIcon)
 {
-  /* Delete the icon if its not the default */
+  /* Delete the icon if its not one of the application defaults or an override */
   if (hIcon &&
       hIcon != g_hIconX &&
       hIcon != g_hSmallIconX &&
diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index fd87c66..d9bec35 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -602,7 +602,9 @@ winDestroyWindowsWindow (WindowPtr pWin)
   MSG			msg;
   winWindowPriv(pWin);
   BOOL			oldstate = winInDestroyWindowsWindow;
-  
+  HICON hIcon;
+  HICON hIconSm;
+
 #if CYGMULTIWINDOW_DEBUG
   ErrorF ("winDestroyWindowsWindow\n");
 #endif
@@ -613,13 +615,22 @@ winDestroyWindowsWindow (WindowPtr pWin)
 
   winInDestroyWindowsWindow = TRUE;
 
+  /* Store the info we need to destroy after this window is gone */
+  hIcon = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_BIG, 0);
+  hIconSm = (HICON)SendMessage(pWinPriv->hWnd, WM_GETICON, ICON_SMALL, 0);
+
   SetProp (pWinPriv->hWnd, WIN_WINDOW_PROP, NULL);
+
   /* Destroy the Windows window */
   DestroyWindow (pWinPriv->hWnd);
 
   /* Null our handle to the Window so referencing it will cause an error */
   pWinPriv->hWnd = NULL;
 
+  /* Destroy any icons we created for this window */
+  winDestroyIcon(hIcon);
+  winDestroyIcon(hIconSm);
+
   /* Process all messages on our queue */
   while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
     {
diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c
index c225a44..0e2f979 100755
--- a/hw/xwin/winwin32rootless.c
+++ b/hw/xwin/winwin32rootless.c
@@ -367,8 +367,8 @@ void
 winMWExtWMDestroyFrame (RootlessFrameID wid)
 {
   win32RootlessWindowPtr pRLWinPriv = (win32RootlessWindowPtr) wid;
-  HICON			hiconClass;
-  HICON			hiconSmClass;
+  HICON			hIcon;
+  HICON			hIconSm;
   HMODULE		hInstance;
   int			iReturn;
   char			pszClass[CLASS_NAME_LENGTH];
@@ -399,8 +399,8 @@ winMWExtWMDestroyFrame (RootlessFrameID wid)
 
   /* Store the info we need to destroy after this window is gone */
   hInstance = (HINSTANCE) GetClassLongPtr (pRLWinPriv->hWnd, GCLP_HMODULE);
-  hiconClass = (HICON) GetClassLongPtr (pRLWinPriv->hWnd, GCLP_HICON);
-  hiconSmClass = (HICON) GetClassLongPtr (pRLWinPriv->hWnd, GCLP_HICONSM);
+  hIcon = (HICON)SendMessage(pRLWinPriv->hWnd, WM_GETICON, ICON_BIG, 0);
+  hIconSm = (HICON)SendMessage(pRLWinPriv->hWnd, WM_GETICON, ICON_SMALL, 0);
   iReturn = GetClassName (pRLWinPriv->hWnd, pszClass, CLASS_NAME_LENGTH);
 
   pRLWinPriv->fClose = TRUE;
@@ -416,14 +416,14 @@ winMWExtWMDestroyFrame (RootlessFrameID wid)
       winDebug ("winMWExtWMDestroyFrame - Unregistering %s: ", pszClass);
 #endif
       iReturn = UnregisterClass (pszClass, hInstance);
-      
+    }
+
 #if CYGMULTIWINDOW_DEBUG
-      winDebug ("winMWExtWMDestroyFramew - %d Deleting Icon: ", iReturn);
+  winDebug ("winMWExtWMDestroyFramew - Deleting Icon\n");
 #endif
-      
-      winDestroyIcon(hiconClass);
-      winDestroyIcon(hiconSmClass);
-    }
+
+  winDestroyIcon(hIcon);
+  winDestroyIcon(hIconSm);
 
 #if CYGMULTIWINDOW_DEBUG
   winDebug ("winMWExtWMDestroyFrame - done\n");
-- 
1.7.1


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


  reply	other threads:[~2010-07-22 20:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-22 18:38 USER/GDI Objects leak with (XWin.exe) Cygwin/X X Server Verion 1.7.6, Build Date 2010-03-18 Amal Khailtash
2010-03-29 17:20 ` Jon TURNEY
2010-03-29 17:21   ` Amal Khailtash
2010-04-05 21:30     ` Jon TURNEY
2010-04-06 21:16       ` Amal Khailtash
2010-04-18 21:09         ` Jon TURNEY
2010-04-20 11:21           ` Amal Khailtash
2010-07-22 20:34             ` Jon TURNEY
2010-07-22 20:35               ` Jon TURNEY [this message]
2010-07-27 15:01               ` Christopher Faylor
2010-07-27 15:26                 ` Csaba Raduly
2010-07-27 17:01                 ` Kenneth Wolcott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1279830920-5748-1-git-send-email-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-xfree@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).