From 290f8be15a1a66c0b2480a9332d3e0c24ab994d1 Mon Sep 17 00:00:00 2001 From: Vineeth TM Date: Thu, 20 Aug 2015 11:02:58 +0900 Subject: [PATCH] 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 --- tests/examples/equalizer/demo.c | 3 +++ tests/icles/equalizer-test.c | 5 ++++- tests/icles/gdkpixbufoverlay-test.c | 4 +++- tests/icles/gdkpixbufsink-test.c | 4 +++- tests/icles/test-oss4.c | 2 ++ tests/icles/videocrop-test.c | 5 ++++- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/examples/equalizer/demo.c b/tests/examples/equalizer/demo.c index 387544de7b..03b4ff6eb6 100644 --- a/tests/examples/equalizer/demo.c +++ b/tests/examples/equalizer/demo.c @@ -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 \n", argv[0]); diff --git a/tests/icles/equalizer-test.c b/tests/icles/equalizer-test.c index 3f9e50e252..883ba33de3 100644 --- a/tests/icles/equalizer-test.c +++ b/tests/icles/equalizer-test.c @@ -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"); diff --git a/tests/icles/gdkpixbufoverlay-test.c b/tests/icles/gdkpixbufoverlay-test.c index efbb972745..45276ee982 100644 --- a/tests/icles/gdkpixbufoverlay-test.c +++ b/tests/icles/gdkpixbufoverlay-test.c @@ -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); diff --git a/tests/icles/gdkpixbufsink-test.c b/tests/icles/gdkpixbufsink-test.c index fbcb13abd5..6c2825a440 100644 --- a/tests/icles/gdkpixbufsink-test.c +++ b/tests/icles/gdkpixbufsink-test.c @@ -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; } diff --git a/tests/icles/test-oss4.c b/tests/icles/test-oss4.c index b2e4b96cb8..adbe442c35 100644 --- a/tests/icles/test-oss4.c +++ b/tests/icles/test-oss4.c @@ -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); diff --git a/tests/icles/videocrop-test.c b/tests/icles/videocrop-test.c index 081fa60f9d..2acfa33738 100644 --- a/tests/icles/videocrop-test.c +++ b/tests/icles/videocrop-test.c @@ -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");