Re: [PATCH C#] Fix two memory leaks in the ConnectCredential.Result setter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



?Hi,

this code is only for the bindings, not the client code. I try to find a solution since times now, but I haven't find an acceptable one for now. I keep searching anyway.

Arnaud

--------------------------------------------------
From: "Daniel Veillard" <veillard@xxxxxxxxxx>
Sent: Thursday, October 28, 2010 9:32 PM
To: "Matthias Bolte" <matthias.bolte@xxxxxxxxxxxxxx>
Cc: <libvir-list@xxxxxxxxxx>
Subject: Re: [PATCH C#] Fix two memory leaks in the ConnectCredential.Result setter

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@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]