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)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 2 Oct 2015 14:24:35 +0000 (17:24 +0300)
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

gst/inter/gstintertest.c
tests/examples/camerabin2/gst-camerabin2-test.c
tests/examples/codecparsers/parse-jpeg.c
tests/examples/gl/gtk/fxtest/fxtest.c
tests/examples/gl/gtk/fxtest/pixbufdrop.c
tests/examples/opencv/gstfacedetect_test.c
tests/examples/playout.c
tools/gst-app-maker

index cff4f0d..3b1abdb 100644 (file)
@@ -85,6 +85,8 @@ main (int argc, char *argv[])
   g_option_context_add_group (context, gst_init_get_option_group ());
   if (!g_option_context_parse (context, &argc, &argv, &error)) {
     g_print ("option parsing failed: %s\n", error->message);
+    g_option_context_free (context);
+    g_clear_error (&error);
     exit (1);
   }
   g_option_context_free (context);
@@ -199,6 +201,7 @@ gst_inter_test_create_pipeline_vts (GstInterTest * intertest)
   if (error) {
     g_print ("pipeline parsing error: %s\n", error->message);
     gst_object_unref (pipeline);
+    g_clear_error (&error);
     return;
   }
 
@@ -236,6 +239,7 @@ gst_inter_test_create_pipeline_server (GstInterTest * intertest)
   if (error) {
     g_print ("pipeline parsing error: %s\n", error->message);
     gst_object_unref (pipeline);
+    g_clear_error (&error);
     return;
   }
 
@@ -352,7 +356,7 @@ gst_inter_test_handle_message (GstBus * bus, GstMessage * message,
 
       gst_message_parse_error (message, &error, &debug);
       gst_inter_test_handle_error (intertest, error, debug);
-      g_error_free (error);
+      g_clear_error (&error);
       g_free (debug);
     }
       break;
@@ -363,7 +367,7 @@ gst_inter_test_handle_message (GstBus * bus, GstMessage * message,
 
       gst_message_parse_warning (message, &error, &debug);
       gst_inter_test_handle_warning (intertest, error, debug);
-      g_error_free (error);
+      g_clear_error (&error);
       g_free (debug);
     }
       break;
@@ -374,7 +378,7 @@ gst_inter_test_handle_message (GstBus * bus, GstMessage * message,
 
       gst_message_parse_info (message, &error, &debug);
       gst_inter_test_handle_info (intertest, error, debug);
-      g_error_free (error);
+      g_clear_error (&error);
       g_free (debug);
     }
       break;
index 90e010a..1c61957 100644 (file)
@@ -428,7 +428,7 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data)
 
       gst_message_parse_error (message, &err, &debug);
       g_print ("Error: %s\n", err->message);
-      g_error_free (err);
+      g_clear_error (&err);
       g_free (debug);
 
       /* Write debug graph to file */
@@ -556,8 +556,7 @@ load_encoding_profile (void)
           gep_filename);
       if (error) {
         GST_WARNING ("Error from file loading: %s", error->message);
-        g_error_free (error);
-        error = NULL;
+        g_clear_error (&error);
       }
     } else {
       prof = gst_encoding_target_get_profile (target, gep_profilename);
@@ -601,7 +600,7 @@ setup_pipeline_element (GstElement * element, const gchar * property_name,
           property_name);
       if (error) {
         GST_ERROR ("%s", error->message);
-        g_error_free (error);
+        g_clear_error (&error);
       }
       res = FALSE;
     }
@@ -1253,6 +1252,8 @@ main (int argc, char *argv[])
   g_option_context_add_group (ctx, gst_init_get_option_group ());
   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
     g_print ("Error initializing: %s\n", err->message);
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     exit (1);
   }
   g_option_context_free (ctx);
index fe42999..ca9cf1b 100644 (file)
@@ -239,7 +239,7 @@ process_file (const gchar * fn)
 
   if (!g_file_get_contents (fn, &data, &size, &err)) {
     g_error ("%s", err->message);
-    g_error_free (err);
+    g_clear_error (&err);
     return;
   }
 
@@ -286,6 +286,8 @@ main (int argc, gchar ** argv)
   g_option_context_add_group (ctx, gst_init_get_option_group ());
   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
     g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     exit (1);
   }
   g_option_context_free (ctx);
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);
index 8ccbda0..9ecf3d0 100644 (file)
@@ -154,6 +154,8 @@ main (gint argc, gchar ** argv)
   g_option_context_add_group (ctx, gst_init_get_option_group ());
   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
     g_print ("Error initializing: %s\n", err->message);
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     exit (1);
   }
   g_option_context_free (ctx);
index c85509a..07048d8 100644 (file)
@@ -680,7 +680,7 @@ playout_item_create_decoder (PlayoutItem * item)
   uri = gst_filename_to_uri (item->fn, &err);
   if (err != NULL) {
     GST_WARNING ("Could not convert '%s' to uri: %s", item->fn, err->message);
-    g_error_free (err);
+    g_clear_error (&err);
     return NULL;
   }
 
@@ -1064,6 +1064,8 @@ main (int argc, char **argv)
       g_printerr ("Error initializing: %s\n", err->message);
     else
       g_printerr ("Error initializing: Unknown error!\n");
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     return 1;
   }
 
index 786cd64..f3c3d1f 100755 (executable)
@@ -151,6 +151,8 @@ main (int argc, char *argv[])
   g_option_context_add_group (context, gst_init_get_option_group ());
   if (!g_option_context_parse (context, &argc, &argv, &error)) {
     g_print ("option parsing failed: %s\n", error->message);
+    g_clear_error (&error);
+    g_option_context_free (context);
     exit (1);
   }
   g_option_context_free (context);
@@ -223,6 +225,7 @@ gst_replace_create_pipeline_playbin (GstReplace *replace, const char *uri)
 
   if (error) {
     g_print("pipeline parsing error: %s\n", error->message);
+    g_clear_error (&error);
     gst_object_unref (pipeline);
     return;
   }
@@ -262,6 +265,7 @@ gst_replace_create_pipeline (GstReplace *replace)
 
   if (error) {
     g_print("pipeline parsing error: %s\n", error->message);
+    g_clear_error (&error);
     gst_object_unref (pipeline);
     return;
   }
@@ -378,6 +382,7 @@ gst_replace_handle_message (GstBus *bus, GstMessage *message,
 
         gst_message_parse_error (message, &error, &debug);
         gst_replace_handle_error (replace, error, debug);
+        g_clear_error (&error);
       }
       break;
     case GST_MESSAGE_WARNING:
@@ -387,6 +392,7 @@ gst_replace_handle_message (GstBus *bus, GstMessage *message,
 
         gst_message_parse_warning (message, &error, &debug);
         gst_replace_handle_warning (replace, error, debug);
+        g_clear_error (&error);
       }
       break;
     case GST_MESSAGE_INFO:
@@ -396,6 +402,7 @@ gst_replace_handle_message (GstBus *bus, GstMessage *message,
 
         gst_message_parse_info (message, &error, &debug);
         gst_replace_handle_info (replace, error, debug);
+        g_clear_error (&error);
       }
       break;
     case GST_MESSAGE_TAG: