Fix few leaks after strdup

https://bugzilla.gnome.org/show_bug.cgi?id=792899
This commit is contained in:
Justin Kim 2018-01-25 22:47:52 +09:00 committed by Sebastian Dröge
parent 37f73f8865
commit 894fee310f
3 changed files with 28 additions and 7 deletions

View file

@ -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<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>();
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<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>();
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;
}

View file

@ -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);
}

View file

@ -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;
}