Modify

Opened 3 months ago

Closed 3 months ago

Last modified 2 months ago

#4028 closed Bug (Works For Me)

Potential for a memory leak in _GDIPlus_BitmapCreateFromMemory

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.16.1 Severity: None
Keywords: Cc:

Description

to fix:
in GDIPlus.au3,
in function _GDIPlus_BitmapCreateFromMemory,
replace this:

        Local Const $hBitmap = _GDIPlus_BitmapCreateFromStream($hStream) ;creates a Bitmap object based on an IStream COM interface
        If @error Then Return SetError(3, 0, 0)
        DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "ulong_ptr", 8 * (1 + @AutoItX64), "uint", 4, "ushort", 23, "uint", 0, "ptr", 0, "ptr", 0, "str", "") ;release memory from $hStream to avoid memory leak

with this:

        Local Const $hBitmap = _GDIPlus_BitmapCreateFromStream($hStream) ;creates a Bitmap object based on an IStream COM interface
        Local $error = @error
        DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "ulong_ptr", 2 * (@AutoItX64 ? 8 : 4), "uint", 4, "ushort", 23, "uint", 0, "ptr", 0, "ptr", 0, "str", "") ;release memory from $hStream to avoid memory leak (2 is the offset of the Release method of IUnknown in its vtable)
        If $error Then Return SetError(3, 0, 0)

Attachments (0)

Change History (6)

comment:2 Changed 3 months ago by Jpm

  • Resolution set to Works For Me
  • Status changed from new to closed

In fact both are doing the same

#AutoIt3Wrapper_UseX64 = N
Local $iCur = 8 * (1 + @AutoItX64)
Local $iPropose = 2 * (@AutoItX64 ? 8 : 4)
If $iCur <> $iPropose Then
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @AutoItX64 = ' & @AutoItX64 & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iCur = ' & $iCur & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iPropose = ' & $iPropose & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
EndIf

comment:3 Changed 2 months ago by anonymous

What on earth?! The memory leak is unrelated to what you've done...

this does NOT matter:

 8 * (1 + @AutoItX64) 
 2 * (@AutoItX64 ? 8 : 4) 

yes they produce the same number -- that's not the point! i've only choosen the second version because it's clear what it does (we need 2nd pointer, where pointer-size depends on AutoIt's bitness -- 8 if x64 and 4 if x32), while first version is cryptic and dumb and "wrong" -- it tells you nothing about what's going on.

the menmory leak WILL and DOES happen every time the error occurs in _GDIPlus_BitmapCreateFromStream.
that's why the COM object (the $hStream, which is only a pointer to the stream returned by DllCall; it's not an AutoIt's object, so the Autoit wil not release it automatically on return or even on exit!) so it HAS TO be released manually before returning from the function _GDIPlus_BitmapCreateFromMemory.

this:

        If @error Then Return SetError(3, 0, 0)
        DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "ulong_ptr", 8 * (1 + @AutoItX64), "uint", 4, "ushort", 23, "uint", 0, "ptr", 0, "ptr", 0, "str", "") ;release memory from $hStream to avoid memory leak

should be replaced by this:

        Local $error = @error
        ;here we MUST release the object by calling its "Release" method(the 2nd method of IUnknown) via "DispCallFunc":
        DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "ulong_ptr", 2 * (@AutoItX64 ? 8 : 4), "uint", 4, "ushort", 23, "uint", 0, "ptr", 0, "ptr", 0, "str", "") ;release memory from $hStream to prevent memory leak
        If $error Then Return SetError(3, 0, 0)

you can leave the 8 * (1 + @AutoItX64) in there if you want. again, this wasn't the issue.

comment:4 follow-up: Changed 2 months ago by anonymous

also, the fistr comment (with the link) is clearly spam. maybe it should be deleted?

comment:5 Changed 2 months ago by anonymous

also, my ticket (#4025 or #4028?) about a small bug in ObjCreateInterface was deleted? why? >:(

comment:6 Changed 2 months ago by anonymous

oops, sorry, my bad!! i was blind -- accidentally grouped tickets by type, and missed mine!! Sorry!!!

comment:7 in reply to: ↑ 4 Changed 2 months ago by Jos

Replying to anonymous:

also, the fistr comment (with the link) is clearly spam. maybe it should be deleted?

Removed... tnx, it is removed now,

... and please try to calm down a little before typing, as the tone of your post in general normally trigger me to simply ignore these posts.
Thanks

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

Action
as closed The ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.