#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 7 weeks ago by Jpm
- Resolution set to Works For Me
- Status changed from new to closed
comment:3 Changed 6 weeks 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: ↓ 7 Changed 6 weeks ago by anonymous
also, the fistr comment (with the link) is clearly spam. maybe it should be deleted?
comment:5 Changed 6 weeks ago by anonymous
comment:6 Changed 6 weeks 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 6 weeks 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.
In fact both are doing the same