[racket] Possible memory leak in MysterX
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
inefficient.
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.