[libvirt] [PATCH C#] Fix two memory leaks in the ConnectCredential.Result setter
Daniel Veillard
veillard at redhat.com
Thu Oct 28 19:32:49 UTC 2010
On Thu, Oct 28, 2010 at 12:38:17PM +0200, Matthias Bolte wrote:
> StringToHGlobalAnsi returns a pointer to unmanaged memory that
> must be freed using FreeHGlobal.
>
> When the setter is called twice the strdup'ed unmanaged string
> from the first call leaks. Free it before assigning it again.
[...]
> +
> + // TODO : this is a temporary workaround for virConnectOpenAuth callback, this should be removed
> + [DllImport("msvcrt.dll", EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
> + public static extern void Free(IntPtr ptr);
> }
[...]
> + IntPtr tmp = Marshal.StringToHGlobalAnsi(value);
> +
> + NativeFunctions.Free(result);
> + result = NativeFunctions.StrDup(tmp);
> resultlen = (uint)value.Length;
> +
> + Marshal.FreeHGlobal(tmp);
This raises 2 questions, how temporary is 'temporary' ;-) ?
And I assume the client code don't need to do similar things, that's
just the bindings, right ?
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list