gstreamer: bad: 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=753854
This commit is contained in:
Vineeth TM 2015-08-20 16:03:29 +09:00 committed by Sebastian Dröge
parent 3b1e095169
commit 8c9ca808af
8 changed files with 32 additions and 10 deletions

View 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;

View 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);

View 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);

View 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);

View 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);

View 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);

View 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;
}

View file

@ -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: