Opened 12 years ago

Closed 11 years ago

#1040 closed Bug (Fixed)

_ScreenCapture_Capture(): GDI object leak with cursor capture

Reported by: rover Owned by: Jpm
Milestone: Component: Standard UDFs
Version: Severity: None
Keywords: _ScreenCapture_Capture Cc:


The returned bitmap handles from _WinAPI_GetIconInfo() are not deleted.
(only $aIcon[4] bitmask has a valid handle when used with cursor)

modified _ScreenCapture_Capture() with added error handling in attached file

Environment = under WIN_XP/Service Pack 2 X86

#include <ScreenCapture.au3>
Global $hBitmap, $hProcess, $aGDIObjs

$hProcess = _WinAPI_GetCurrentProcess()
If @error Then $hProcess = 0xFFFFFFFF

While 1
	$hBitmap = _ScreenCapture_Capture("", 0, 0, 400, 300, True)
	$aGDIObjs = DllCall("user32.dll", "int", "GetGuiResources", "hwnd", $hProcess, "int", 0)
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : GDI Objects = ' & $aGDIObjs[0] & @CRLF)
	If $aGDIObjs[0] > 40 Then Exit

Attachments (1)

_ScreenCapture_Capture.au3 (4.4 KB) - added by rover 12 years ago.
_ScreenCapture_Capture() UDF with added error handling

Download all attachments as: .zip

Change History (7)

Changed 12 years ago by rover

_ScreenCapture_Capture() UDF with added error handling

comment:1 Changed 12 years ago by Jpm

  • Milestone set to
  • Owner changed from Gary to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed in version:

comment:2 Changed 12 years ago by djbarnes@…

this needs to be reopened as it exists again in

comment:3 Changed 12 years ago by Valik

  • Resolution Fixed deleted
  • Status changed from closed to reopened

comment:4 Changed 12 years ago by TicketCleanup

  • Milestone deleted

Automatic ticket cleanup.

comment:5 Changed 12 years ago by Beege

I'm pretty sure the problem here is that _WinAPI_GetIconInfo returns TWO bitmaps and we are only deleting ONE of them. The cursor section of the function needs to check if $aIcon[5] is valid bitmap and delete if it is. Depending on what cursor is being displayed $aIcon[5] may not alway be a valid bitmap. From the tests I've done, when the cursor is an I-beam, the bitmap will NOT be valid. Almost all other ones were valid.

	If $fCursor Then
		Local $aCursor = _WinAPI_GetCursorInfo()
		If $aCursor[1] Then
			Local $hIcon = _WinAPI_CopyIcon($aCursor[2])
			Local $aIcon = _WinAPI_GetIconInfo($hIcon)
			_WinAPI_DeleteObject($aIcon[4]); delete bitmap mask return by _WinAPI_GetIconInfo()
	---->>>>>>>>>>>>If $aIcon[5] <> 0 Then _WinAPI_DeleteObject($aIcon[5]); delete bitmap hbmColor return by _WinAPI_GetIconInfo()
			_WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon)

comment:6 Changed 11 years ago by Jpm

  • Milestone set to
  • Resolution set to Fixed
  • Status changed from reopened to closed

Fixed by revision [5768] in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Jpm.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.