gstreamer: bad: Fix memory leaks when context parse fails
authorVineeth TM <vineeth.tm@samsung.com>
Thu, 20 Aug 2015 07:03:29 +0000 (16:03 +0900)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:09 +0000 (19:32 +0000)
When g_option_context_parse fails, context and error variables are not getting free'd
which results in memory leaks. Free'ing the same.

And replacing g_error_free with g_clear_error, which checks if the error being passed
is not NULL and sets the variable to NULL on free'ing.

https://bugzilla.gnome.org/show_bug.cgi?id=753854

tests/examples/gl/gtk/fxtest/fxtest.c
tests/examples/gl/gtk/fxtest/pixbufdrop.c

index f83f189..17860eb 100644 (file)
@@ -76,7 +76,7 @@ end_stream_cb (GstBus * bus, GstMessage * message, GstElement * pipeline)
       gst_message_parse_error (message, &err, &debug);
 
       g_print ("Error: %s\n", err->message);
-      g_error_free (err);
+      g_clear_error (&err);
 
       if (debug) {
         g_print ("Debug details: %s\n", debug);
@@ -202,6 +202,8 @@ main (gint argc, gchar * argv[])
   g_option_context_add_group (context, gtk_get_option_group (TRUE));
   if (!g_option_context_parse (context, &argc, &argv, &error)) {
     g_print ("Inizialization error: %s\n", GST_STR_NULL (error->message));
+    g_option_context_free (context);
+    g_clear_error (&error);
     return -1;
   }
   g_option_context_free (context);
index 463add3..69bf3af 100644 (file)
@@ -206,6 +206,8 @@ main (gint argc, gchar * argv[])
   g_option_context_add_group (context, gtk_get_option_group (TRUE));
   if (!g_option_context_parse (context, &argc, &argv, &error)) {
     g_print ("Inizialization error: %s\n", GST_STR_NULL (error->message));
+    g_option_context_free (context);
+    g_clear_error (&error);
     return -1;
   }
   g_option_context_free (context);