gstreamer: base: Fix memory leaks when context parse fails.
authorVineeth TM <vineeth.tm@samsung.com>
Thu, 20 Aug 2015 06:59:15 +0000 (15:59 +0900)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 2 Oct 2015 14:26:27 +0000 (17:26 +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=753852

gst-libs/gst/tag/mklicensestables.c
tests/examples/encoding/encoding.c
tests/examples/playback/playback-test.c
tests/examples/seek/jsseek.c
tests/examples/seek/scrubby.c
tests/icles/stress-playbin.c
tests/icles/test-effect-switch.c
tools/gst-device-monitor.c
tools/gst-discoverer.c
tools/gst-play.c

index 03abc58..87d1205 100644 (file)
@@ -415,6 +415,7 @@ parse_license_rdf (const gchar * fn, const gchar * rdf)
 
   if (!g_markup_parse_context_parse (ctx, rdf, -1, &err)) {
     g_error ("Error parsing file %s: %s\n", fn, err->message);
+    g_clear_error (&err);
   }
 
   licenses = g_list_append (licenses, license);
@@ -433,6 +434,7 @@ read_licenses (const gchar * licenses_dir)
 
   if (dir == NULL)
     g_error ("Failed to g_dir_open('%s'): %s", licenses_dir, err->message);
+  g_clear_error (&err);
 
   while ((name = g_dir_read_name (dir))) {
     gchar *fn, *rdf;
@@ -443,7 +445,7 @@ read_licenses (const gchar * licenses_dir)
       g_free (rdf);
     } else {
       g_printerr ("Could not read file '%s': %s\n", fn, err->message);
-      g_error_free (err);
+      g_clear_error (&err);
       err = NULL;
     }
     g_free (fn);
@@ -722,6 +724,8 @@ main (int argc, char **argv)
   g_option_context_add_main_entries (ctx, options, NULL);
   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
     g_printerr ("Error initializing: %s\n", err->message);
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     exit (1);
   }
   g_option_context_free (ctx);
index 1861f81..83820b7 100644 (file)
@@ -399,6 +399,8 @@ main (int argc, char **argv)
 
   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);
   }
 
index d458c2b..2716464 100644 (file)
@@ -1466,6 +1466,7 @@ shot_cb (GtkButton * button, PlaybackApp * app)
     /* save the pixbuf */
     gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
     gst_buffer_unmap (buffer, &map);
+    g_clear_error (&error);
 
   done:
     gst_sample_unref (sample);
@@ -3414,6 +3415,8 @@ main (int argc, char **argv)
 
   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 72bca95..8a472af 100644 (file)
@@ -961,9 +961,8 @@ static GstElement *
 make_parselaunch_pipeline (const gchar * description)
 {
   GstElement *pipeline;
-  GError *error = NULL;
 
-  pipeline = gst_parse_launch (description, &error);
+  pipeline = gst_parse_launch (description, NULL);
 
   seekable_elements = g_list_prepend (seekable_elements, pipeline);
 
@@ -2057,9 +2056,7 @@ shot_cb (GtkButton * button, gpointer data)
     /* save the pixbuf */
     gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
     gst_buffer_unmap (buffer, &map);
-
-    /* save the pixbuf */
-    gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
+    g_clear_error (&error);
 
   done:
     gst_buffer_unref (buffer);
@@ -2624,7 +2621,7 @@ read_joystick (GIOChannel * source, GIOCondition condition, gpointer user_data)
       &bytes_read, &err);
   if (err) {
     g_print ("error reading from joystick: %s", err->message);
-    g_error_free (err);
+    g_clear_error (&err);
     return FALSE;
   } else if (bytes_read != sizeof (struct js_event)) {
     g_print ("error reading joystick, read %u bytes of %u\n",
@@ -2678,6 +2675,8 @@ main (int argc, char **argv)
 
   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 c5c8d67..8afcc88 100644 (file)
@@ -456,6 +456,8 @@ main (int argc, char **argv)
 
   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);
   }
 
index 24498f9..00bc48e 100644 (file)
@@ -34,7 +34,7 @@ play_file (const gint delay, const gchar * uri)
 
         gst_message_parse_error (msg, &gerror, &debug);
         gst_object_default_error (GST_MESSAGE_SRC (msg), gerror, debug);
-        g_error_free (gerror);
+        g_clear_error (&gerror);
         g_free (debug);
         break;
       }
@@ -103,6 +103,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", GST_STR_NULL (err->message));
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     exit (1);
   }
   g_option_context_free (ctx);
index 79b423d..fc54a4d 100644 (file)
@@ -128,7 +128,7 @@ bus_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
 
       gst_message_parse_error (msg, &err, &dbg);
       gst_object_default_error (msg->src, err, dbg);
-      g_error_free (err);
+      g_clear_error (&err);
       g_free (dbg);
       g_main_loop_quit (loop);
       break;
@@ -158,6 +158,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);
     return 1;
   }
   g_option_context_free (ctx);
index c4a1d5e..e9c2ed9 100644 (file)
@@ -166,6 +166,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", GST_STR_NULL (err->message));
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     return 1;
   }
   g_option_context_free (ctx);
index 16468ae..37bb985 100644 (file)
@@ -487,7 +487,7 @@ process_file (GstDiscoverer * dc, const gchar * filename)
 
     if (err) {
       g_warning ("Couldn't convert filename to URI: %s\n", err->message);
-      g_error_free (err);
+      g_clear_error (&err);
       return;
     }
   } else {
@@ -498,9 +498,9 @@ process_file (GstDiscoverer * dc, const gchar * filename)
     g_print ("Analyzing %s\n", uri);
     info = gst_discoverer_discover_uri (dc, uri, &err);
     print_info (info, err);
-    if (err)
-      g_error_free (err);
-    gst_discoverer_info_unref (info);
+    g_clear_error (&err);
+    if (info)
+      gst_discoverer_info_unref (info);
   } else {
     gst_discoverer_discover_uri_async (dc, uri);
   }
index 15c9aa2..40361c0 100644 (file)
@@ -352,7 +352,7 @@ play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
       g_printerr ("WARNING %s\n", err->message);
       if (dbg != NULL)
         g_printerr ("WARNING debug information: %s\n", dbg);
-      g_error_free (err);
+      g_clear_error (&err);
       g_free (dbg);
       break;
     }
@@ -368,7 +368,7 @@ play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
       g_printerr ("ERROR %s for %s\n", err->message, play->uris[play->cur_idx]);
       if (dbg != NULL)
         g_printerr ("ERROR debug information: %s\n", dbg);
-      g_error_free (err);
+      g_clear_error (&err);
       g_free (dbg);
 
       /* flush any other error messages from the bus and clean up */
@@ -1139,6 +1139,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", GST_STR_NULL (err->message));
+    g_option_context_free (ctx);
+    g_clear_error (&err);
     return 1;
   }
   g_option_context_free (ctx);