From: Vineeth TM Date: Thu, 20 Aug 2015 06:59:15 +0000 (+0900) Subject: gstreamer: base: Fix memory leaks when context parse fails. X-Git-Tag: 1.19.3~511^2~3313 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e5f7f27f56e567ab31bb3986f4963fc30c39443;p=platform%2Fupstream%2Fgstreamer.git gstreamer: base: Fix memory leaks when context parse fails. 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 --- diff --git a/gst-libs/gst/tag/mklicensestables.c b/gst-libs/gst/tag/mklicensestables.c index 03abc58..87d1205 100644 --- a/gst-libs/gst/tag/mklicensestables.c +++ b/gst-libs/gst/tag/mklicensestables.c @@ -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); diff --git a/tests/examples/encoding/encoding.c b/tests/examples/encoding/encoding.c index 1861f81..83820b7 100644 --- a/tests/examples/encoding/encoding.c +++ b/tests/examples/encoding/encoding.c @@ -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); } diff --git a/tests/examples/playback/playback-test.c b/tests/examples/playback/playback-test.c index d458c2b..2716464 100644 --- a/tests/examples/playback/playback-test.c +++ b/tests/examples/playback/playback-test.c @@ -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); diff --git a/tests/examples/seek/jsseek.c b/tests/examples/seek/jsseek.c index 72bca95..8a472af 100644 --- a/tests/examples/seek/jsseek.c +++ b/tests/examples/seek/jsseek.c @@ -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); diff --git a/tests/examples/seek/scrubby.c b/tests/examples/seek/scrubby.c index c5c8d67..8afcc88 100644 --- a/tests/examples/seek/scrubby.c +++ b/tests/examples/seek/scrubby.c @@ -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); } diff --git a/tests/icles/stress-playbin.c b/tests/icles/stress-playbin.c index 24498f9..00bc48e 100644 --- a/tests/icles/stress-playbin.c +++ b/tests/icles/stress-playbin.c @@ -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); diff --git a/tests/icles/test-effect-switch.c b/tests/icles/test-effect-switch.c index 79b423d..fc54a4d 100644 --- a/tests/icles/test-effect-switch.c +++ b/tests/icles/test-effect-switch.c @@ -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); diff --git a/tools/gst-device-monitor.c b/tools/gst-device-monitor.c index c4a1d5e..e9c2ed9 100644 --- a/tools/gst-device-monitor.c +++ b/tools/gst-device-monitor.c @@ -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); diff --git a/tools/gst-discoverer.c b/tools/gst-discoverer.c index 16468ae..37bb985 100644 --- a/tools/gst-discoverer.c +++ b/tools/gst-discoverer.c @@ -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); } diff --git a/tools/gst-play.c b/tools/gst-play.c index 15c9aa2..40361c0 100644 --- a/tools/gst-play.c +++ b/tools/gst-play.c @@ -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);