https://bugs.winehq.org/show_bug.cgi?id=54456
Bug ID: 54456 Summary: vbscript memory leak in For Each with SafeArray as group Product: Wine Version: 7.21 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: vbscript Assignee: wine-bugs@winehq.org Reporter: jsm174@gmail.com Distribution: ---
While porting Visual Pinball to cross platform, I started using XCode Instruments to find some outstanding memory leaks.
Given the following code:
Class cvpmDictionary Private mDict Private Sub Class_Initialize : Set mDict = CreateObject("Scripting.Dictionary") : mDict("key") = "value" : End Sub Public Function Keys : Keys = mDict.Keys : End Function End Class
Dim vpDict Set vpDict = New cvpmDictionary
Sub RollingTimer_Timer For Each obj In vpDict.Keys : Debug.Print "Key" : Next End Sub
RollingTimer_Timer gets executed a few times a second. This seems to leak the vpDict.Keys SafeArray.
If I change the code to:
Sub RollingTimer_Timer Dim x x = vpDict.Keys For Each obj In x : Debug.Print "Key" : Next End Sub
No memory leaks are detected. In this case, release_exec calls VariantClear for ctx->vars which frees the SafeArray in X.
In the first case, vpDict.Keys doesn't appear to be stored anywhere, so nothing is freed in release_exec.
https://bugs.winehq.org/show_bug.cgi?id=54456
--- Comment #1 from Jason Millard jsm174@gmail.com --- So I think I have a solution for this. I can submit a MR if you think this is correct.
When this code is executed:
For Each obj In vpDict.Keys : Debug.Print "Key" : Next
"stack_pop_deref(ctx, &v)" returns variant_val_t with "owned" set to true.
I added an "owned" flag to "safearray_iter", and the "create_safearray_iter" function
typedef struct { IEnumVARIANT IEnumVARIANT_iface;
LONG ref;
SAFEARRAY *sa; BOOL owned; ULONG i, size; } safearray_iter;
HRESULT create_safearray_iter(SAFEARRAY *sa, BOOL owned, IEnumVARIANT **ev)
When "safearray_iter_IEnumVARIANT_Release" is called, we checked owned and then free the array.
if(!ref) { if(This->sa) { SafeArrayUnlock(This->sa); if (This->owned) SafeArrayDestroy(This->sa); } free(This); }
I tested this and I know longer have any memory leaks.
https://bugs.winehq.org/show_bug.cgi?id=54456
Jason Millard jsm174@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Jason Millard jsm174@gmail.com --- Fixed in a8c319cad691a53cfd333ab72dbbeac4558f7c75
https://bugs.winehq.org/show_bug.cgi?id=54456
Zeb Figura z.figura12@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |z.figura12@gmail.com Fixed by SHA1| |a8c319cad691a53cfd333ab72db | |beac4558f7c75
https://bugs.winehq.org/show_bug.cgi?id=54456
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #3 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 8.2.
https://bugs.winehq.org/show_bug.cgi?id=54456
Michael Stefaniuc mstefani@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |8.0.x
https://bugs.winehq.org/show_bug.cgi?id=54456
Michael Stefaniuc mstefani@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|8.0.x |---
--- Comment #4 from Michael Stefaniuc mstefani@winehq.org --- Removing the 8.0.x milestone from bug fixes included in 8.0.1.