summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de>2004-04-27 18:07:58 +0000
committerAlexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de>2004-04-27 18:07:58 +0000
commit4b7bde21a64ae03ada5d16434f5ae158f919e3e0 (patch)
tree67e93cdba091b724907d6042508e2e5027b22fca
parent9a6e22ebfb4f93b240e42249a230d76afc041216 (diff)
fix severe GDI leak. GetIconInfo allocated new bitmaps which were never
deleted
-rw-r--r--hw/xwin/wincursor.c59
1 files changed, 28 insertions, 31 deletions
diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c
index 0acc497c4..e105c58fd 100644
--- a/hw/xwin/wincursor.c
+++ b/hw/xwin/wincursor.c
@@ -358,6 +358,7 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
}
free (lpBits);
+
if (hAnd && hXor)
{
ii.fIcon = FALSE;
@@ -367,20 +368,32 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
ii.hbmColor = hXor;
hCursor = (HCURSOR) CreateIconIndirect( &ii );
- GetIconInfo(hCursor, &ii);
- if (ii.fIcon)
+ if (hCursor == NULL)
+ winW32Error(2, GetLastError(), "winLoadCursor - CreateIconIndirect failed: %s\n");
+ else
{
- HCURSOR hCursor2;
- WIN_DEBUG_MSG("winLoadCursor: CreateIconIndirect returned no "
- "cursor. Trying again.\n");
-
- ii.fIcon = FALSE;
- ii.xHotspot = pCursor->bits->xhot;
- ii.yHotspot = pCursor->bits->yhot;
- hCursor2 = (HCURSOR) CreateIconIndirect( &ii );
-
- DestroyIcon(hCursor);
- hCursor = hCursor2;
+ GetIconInfo(hCursor, &ii);
+ if (ii.fIcon)
+ {
+ WIN_DEBUG_MSG("winLoadCursor: CreateIconIndirect returned no cursor. Trying again.\n");
+
+ DestroyCursor(hCursor);
+
+ ii.fIcon = FALSE;
+ ii.xHotspot = pCursor->bits->xhot;
+ ii.yHotspot = pCursor->bits->yhot;
+ hCursor = (HCURSOR) CreateIconIndirect( &ii );
+
+ if (hCursor == NULL)
+ winW32Error(2, GetLastError(), "winLoadCursor - CreateIconIndirect failed: %s\n");
+
+ /* GetIconInfo creates new bitmaps. Destroy them again */
+ if (ii.hbmMask)
+ DeleteObject(ii.hbmMask);
+ if (ii.hbmColor)
+ DeleteObject(ii.hbmColor);
+
+ }
}
}
@@ -398,28 +411,12 @@ winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
pCursor->bits->xhot, pCursor->bits->yhot,
pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy,
pAnd, pXor);
+ if (hCursor == NULL)
+ winW32Error(2, GetLastError(), "winLoadCursor - CreateCursor failed: %s\n");
}
free (pAnd);
free (pXor);
- if (hCursor == NULL)
- {
- LPVOID lpMsgBuf;
-
- /* Display a fancy error message */
- FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError (),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0, NULL);
-
- winErrorFVerb (2, "winLoadCursor - CreateCursor failed\n"
- "\t%s\n", (LPSTR)lpMsgBuf);
- LocalFree (lpMsgBuf);
- }
return hCursor;
}