gstreamer: good: tests: 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

https://bugzilla.gnome.org/show_bug.cgi?id=753853
This commit is contained in:
Vineeth TM 2015-08-20 11:02:58 +09:00 committed by Sebastian Dröge
parent b814d7ed25
commit 290f8be15a
6 changed files with 19 additions and 4 deletions

View file

@ -180,8 +180,11 @@ 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);
if (argc < 2) {
g_print ("Usage: %s <uri to play>\n", argv[0]);

View file

@ -55,7 +55,7 @@ check_bus (GstClockTime max_wait_time)
gst_message_parse_error (msg, &err, &debug);
GST_ERROR ("ERROR: %s [%s]", err->message, debug);
g_print ("\n===========> ERROR: %s\n%s\n\n", err->message, debug);
g_error_free (err);
g_clear_error (&err);
g_free (debug);
}
@ -186,8 +186,11 @@ main (int argc, char **argv)
if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
g_error ("Error parsing command line options: %s", opt_err->message);
g_option_context_free (ctx);
g_clear_error (&opt_err);
return -1;
}
g_option_context_free (ctx);
GST_DEBUG_CATEGORY_INIT (equalizer_test_debug, "equalizertest", 0, "eqtest");

View file

@ -151,7 +151,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;
@ -218,6 +218,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);

View file

@ -175,7 +175,7 @@ bus_message_cb (GstBus * bus, GstMessage * msg, AppInfo * info)
gst_message_parse_error (msg, &err, &dbg);
g_error ("Error: %s\n%s\n", err->message, (dbg) ? dbg : "");
g_error_free (err);
g_clear_error (&err);
g_free (dbg);
break;
}
@ -345,6 +345,8 @@ main (int argc, char **argv)
if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
g_error ("Error parsing command line options: %s", opt_err->message);
g_option_context_free (ctx);
g_clear_error (&opt_err);
return -1;
}

View file

@ -115,6 +115,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);

View file

@ -53,7 +53,7 @@ check_bus_for_errors (GstBus * bus, GstClockTime max_wait_time)
gst_message_parse_error (msg, &err, &debug);
GST_ERROR ("ERROR: %s [%s]", err->message, debug);
g_print ("\n===========> ERROR: %s\n%s\n\n", err->message, debug);
g_error_free (err);
g_clear_error (&err);
g_free (debug);
gst_message_unref (msg);
}
@ -201,8 +201,11 @@ main (int argc, char **argv)
if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
g_error ("Error parsing command line options: %s", opt_err->message);
g_option_context_free (ctx);
g_clear_error (&opt_err);
return -1;
}
g_option_context_free (ctx);
GST_DEBUG_CATEGORY_INIT (videocrop_test_debug, "videocroptest", 0, "vctest");