[racket] Possible memory leak in MysterX

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Mar 2 12:54:37 EST 2011

At Wed, 02 Mar 2011 17:23:56 +0000, José Lopes wrote:
> I think the following code can lead to memory leak because 
> doTypeDescFromTypeInfo might call scheme_signal_error
> static
> MX_TYPEDESC *typeDescFromTypeInfo(LPCTSTR name, INVOKEKIND invKind,
>                                    ITypeInfo *pITypeInfo)
> {
>    BSTR unicodeName;
>    MX_TYPEDESC *retval;
>    unicodeName = textToBSTR(name, strlen(name));
>    retval = doTypeDescFromTypeInfo(unicodeName, invKind, pITypeInfo);
>    SysFreeString(unicodeName);
>    return retval;
> }

Yes, that looks like a leak.

> There should be some construct similar to try...catch...finally using 
> the scheme_* primitives surrounding the call to doTypeDescFromTypeInfo 
> and SysFreeString.

I would try to avoid that, because it's so messy and possibly

In this case, I think I'd try to rewrite so that the original `name'
could be passed to doTypeDescFromTypeInfo(), and then
doTypeDescFromTypeInfo() would convert as needed.

Posted on the users mailing list.