diff --git a/sources/custom/Application.cs b/sources/custom/Application.cs index dd8682afae..27ef4c5c2e 100644 --- a/sources/custom/Application.cs +++ b/sources/custom/Application.cs @@ -45,10 +45,13 @@ namespace Gst { public static void Init(ref string[] argv) { int cnt_argv = argv == null ? 0 : argv.Length; - IntPtr[] native_argv = new IntPtr [cnt_argv]; + System.Collections.Generic.List native_arg_list = new System.Collections.Generic.List(); for (int i = 0; i < cnt_argv; i++) - native_argv [i] = GLib.Marshaller.StringToPtrGStrdup(argv[i]); + native_arg_list.Add (GLib.Marshaller.StringToPtrGStrdup(argv[i])); + IntPtr[] native_argv = native_arg_list.ToArray(); gst_init(ref cnt_argv, ref native_argv); + foreach (var native_arg in native_arg_list) + GLib.Marshaller.Free (native_arg); } [DllImport("libgstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] @@ -66,11 +69,14 @@ namespace Gst { public static bool InitCheck(ref string[] argv) { int cnt_argv = argv == null ? 0 : argv.Length; - IntPtr[] native_argv = new IntPtr [cnt_argv]; + System.Collections.Generic.List native_arg_list = new System.Collections.Generic.List(); for (int i = 0; i < cnt_argv; i++) - native_argv [i] = GLib.Marshaller.StringToPtrGStrdup(argv[i]); + native_arg_list.Add (GLib.Marshaller.StringToPtrGStrdup(argv[i])); + IntPtr[] native_argv = native_arg_list.ToArray(); IntPtr error = IntPtr.Zero; bool ret = gst_init_check(ref cnt_argv, ref native_argv, out error); + foreach (var native_arg in native_arg_list) + GLib.Marshaller.Free (native_arg); if (error != IntPtr.Zero) throw new GLib.GException (error); return ret; } diff --git a/sources/custom/DeviceProvider.cs b/sources/custom/DeviceProvider.cs index a8091603cc..463823d633 100644 --- a/sources/custom/DeviceProvider.cs +++ b/sources/custom/DeviceProvider.cs @@ -43,8 +43,11 @@ namespace Gst { public void AddStaticMetadata(string key, string value) { IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (key); - gst_device_provider_class_add_static_metadata(LookupGType().GetClassPtr (), native_key, GLib.Marshaller.StringToPtrGStrdup(value)); + IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value); + gst_device_provider_class_add_static_metadata(LookupGType().GetClassPtr (), native_key, native_value); + GLib.Marshaller.Free (native_key); + GLib.Marshaller.Free (native_value); } [DllImport("libgstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] @@ -66,7 +69,17 @@ namespace Gst { static extern void gst_device_provider_class_set_static_metadata(IntPtr klass, IntPtr longname, IntPtr classification, IntPtr description, IntPtr author); public void SetStaticMetadata(string longname, string classification, string description, string author) { - gst_device_provider_class_set_static_metadata(LookupGType().GetClassPtr (), GLib.Marshaller.StringToPtrGStrdup(longname), GLib.Marshaller.StringToPtrGStrdup(classification), GLib.Marshaller.StringToPtrGStrdup(description), GLib.Marshaller.StringToPtrGStrdup(author)); + IntPtr native_longname = GLib.Marshaller.StringToPtrGStrdup (longname); + IntPtr native_classification = GLib.Marshaller.StringToPtrGStrdup (classification); + IntPtr native_description = GLib.Marshaller.StringToPtrGStrdup (description); + IntPtr native_author = GLib.Marshaller.StringToPtrGStrdup (author); + + gst_device_provider_class_set_static_metadata(LookupGType().GetClassPtr (), native_longname, native_classification, native_description, native_author); + + GLib.Marshaller.Free (native_longname); + GLib.Marshaller.Free (native_classification); + GLib.Marshaller.Free (native_description); + GLib.Marshaller.Free (native_author); } diff --git a/sources/custom/Object.cs b/sources/custom/Object.cs index d4284241a9..d0458da355 100644 --- a/sources/custom/Object.cs +++ b/sources/custom/Object.cs @@ -55,7 +55,8 @@ namespace Gst { if (PropertyNameCache.ContainsKey (name)) return PropertyNameCache [name]; - var ptr = g_object_class_find_property (Marshal.ReadIntPtr (Handle), GLib.Marshaller.StringToPtrGStrdup (name)); + IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name); + var ptr = g_object_class_find_property (Marshal.ReadIntPtr (Handle), native_name); var result = ptr != IntPtr.Zero; // just cache the positive results because there might @@ -63,6 +64,7 @@ namespace Gst { if (result) PropertyNameCache [name] = result; + GLib.Marshaller.Free (native_name); return result; }