mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 16:26:39 +00:00
gstreamer: 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=753851
This commit is contained in:
parent
d3e9f55302
commit
215cfcf993
10 changed files with 45 additions and 13 deletions
|
@ -915,7 +915,7 @@ main (int argc, char *argv[])
|
|||
|
||||
if (error != NULL) {
|
||||
g_print ("could not construct pipeline: %s\n", error->message);
|
||||
g_error_free (error);
|
||||
g_clear_error (&error);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
|
@ -1475,7 +1475,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;
|
||||
|
@ -1505,6 +1505,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_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
return 1;
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
|
|
@ -127,8 +127,11 @@ main (gint argc, gchar **argv)
|
|||
* calls gtk_init() and gst_init() */
|
||||
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
||||
g_print ("Error initializing: %s\n", err->message);
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
exit (1);
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
||||
/* any filenames we got passed on the command line? parse them! */
|
||||
if (cmd_filenames != NULL) {
|
||||
|
|
|
@ -102,9 +102,11 @@ main (int argc,
|
|||
g_option_context_add_group (ctx, gst_init_get_option_group ());
|
||||
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
||||
g_print ("Failed to initialize: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
return 1;
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
||||
printf ("Run me with --help to see the Application options appended.\n");
|
||||
|
||||
|
|
|
@ -235,6 +235,8 @@ main (int argc, char *argv[])
|
|||
g_printerr ("Error initializing: %s\n", GST_STR_NULL (err->message));
|
||||
else
|
||||
g_printerr ("Error initializing: Unknown error!\n");
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
exit (1);
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
|
|
@ -98,6 +98,7 @@ have_socket_data_cb (GSocket * socket, GIOCondition condition,
|
|||
read = g_socket_receive (socket, buffer, sizeof (buffer), NULL, &err);
|
||||
if (read == -1)
|
||||
g_error ("Failed to read from socket: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
|
||||
if (verbose)
|
||||
g_message ("Received %" G_GSSIZE_FORMAT " bytes from %s socket", read,
|
||||
|
@ -111,6 +112,7 @@ have_socket_data_cb (GSocket * socket, GIOCondition condition,
|
|||
sizeof (header), &written, &err);
|
||||
if (status == G_IO_STATUS_ERROR) {
|
||||
g_error ("Failed to write to stdout: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
} else if (status == G_IO_STATUS_EOF) {
|
||||
g_message ("EOF on stdout");
|
||||
exit (0);
|
||||
|
@ -124,6 +126,7 @@ have_socket_data_cb (GSocket * socket, GIOCondition condition,
|
|||
g_io_channel_write_chars (stdout_channel, buffer, read, &written, &err);
|
||||
if (status == G_IO_STATUS_ERROR) {
|
||||
g_error ("Failed to write to stdout: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
} else if (status == G_IO_STATUS_EOF) {
|
||||
g_message ("EOF on stdout");
|
||||
exit (0);
|
||||
|
@ -157,6 +160,7 @@ have_stdin_data_cb (GIOChannel * channel, GIOCondition condition,
|
|||
&read, &err);
|
||||
if (status == G_IO_STATUS_ERROR) {
|
||||
g_error ("Failed to read from stdin: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
} else if (status == G_IO_STATUS_EOF) {
|
||||
g_message ("EOF on stdin");
|
||||
exit (0);
|
||||
|
@ -171,6 +175,7 @@ have_stdin_data_cb (GIOChannel * channel, GIOCondition condition,
|
|||
status = g_io_channel_read_chars (channel, buffer, header.size, &read, &err);
|
||||
if (status == G_IO_STATUS_ERROR) {
|
||||
g_error ("Failed to read from stdin: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
} else if (status == G_IO_STATUS_EOF) {
|
||||
g_message ("EOF on stdin");
|
||||
exit (0);
|
||||
|
@ -192,7 +197,7 @@ have_stdin_data_cb (GIOChannel * channel, GIOCondition condition,
|
|||
g_error ("Failed to write to socket: %s", err->message);
|
||||
else if (written != header.size)
|
||||
g_error ("Unexpected write size: %" G_GSSIZE_FORMAT, written);
|
||||
|
||||
g_clear_error (&err);
|
||||
if (verbose)
|
||||
g_message ("Sent %" G_GSSIZE_FORMAT " bytes to %s socket", read,
|
||||
(header.type == TYPE_EVENT ? "event" : "general"));
|
||||
|
@ -219,12 +224,14 @@ setup_sockets (void)
|
|||
G_SOCKET_PROTOCOL_UDP, &err);
|
||||
if (!socket_event)
|
||||
g_error ("Couldn't create event socket: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
|
||||
socket_general =
|
||||
g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
|
||||
G_SOCKET_PROTOCOL_UDP, &err);
|
||||
if (!socket_general)
|
||||
g_error ("Couldn't create general socket: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
|
||||
/* Bind sockets */
|
||||
bind_addr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
|
||||
|
@ -458,18 +465,22 @@ setup_sockets (void)
|
|||
if (!g_socket_join_multicast_group (socket_event, mcast_addr, FALSE, NULL,
|
||||
&err))
|
||||
g_error ("Couldn't join multicast group: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
if (!g_socket_join_multicast_group (socket_general, mcast_addr, FALSE,
|
||||
NULL, &err))
|
||||
g_error ("Couldn't join multicast group: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
}
|
||||
} else {
|
||||
/* Join multicast group without any interface */
|
||||
if (!g_socket_join_multicast_group (socket_event, mcast_addr, FALSE, NULL,
|
||||
&err))
|
||||
g_error ("Couldn't join multicast group: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
if (!g_socket_join_multicast_group (socket_general, mcast_addr, FALSE, NULL,
|
||||
&err))
|
||||
g_error ("Couldn't join multicast group: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
}
|
||||
|
||||
event_saddr = g_inet_socket_address_new (mcast_addr, PTP_EVENT_PORT);
|
||||
|
@ -592,6 +603,7 @@ write_clock_id (void)
|
|||
sizeof (header), &written, &err);
|
||||
if (status == G_IO_STATUS_ERROR) {
|
||||
g_error ("Failed to write to stdout: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
} else if (status == G_IO_STATUS_EOF) {
|
||||
g_message ("EOF on stdout");
|
||||
exit (0);
|
||||
|
@ -606,6 +618,7 @@ write_clock_id (void)
|
|||
(const gchar *) clock_id_array, sizeof (clock_id_array), &written, &err);
|
||||
if (status == G_IO_STATUS_ERROR) {
|
||||
g_error ("Failed to write to stdout: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
} else if (status == G_IO_STATUS_EOF) {
|
||||
g_message ("EOF on stdout");
|
||||
exit (0);
|
||||
|
@ -654,6 +667,7 @@ main (gint argc, gchar ** argv)
|
|||
g_option_context_add_main_entries (opt_ctx, opt_entries, NULL);
|
||||
if (!g_option_context_parse (opt_ctx, &argc, &argv, &err))
|
||||
g_error ("Error parsing options: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (opt_ctx);
|
||||
|
||||
setup_sockets ();
|
||||
|
|
|
@ -157,7 +157,7 @@ event_loop (GstElement * bin)
|
|||
gst_message_parse_warning (msg, &err, &dbg);
|
||||
GST_WARNING_OBJECT (GST_MESSAGE_SRC (msg), "%s (%s)", err->message,
|
||||
(dbg ? dbg : "no details"));
|
||||
g_error_free (err);
|
||||
g_clear_error (&err);
|
||||
g_free (dbg);
|
||||
break;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ event_loop (GstElement * bin)
|
|||
gst_message_parse_error (msg, &err, &dbg);
|
||||
GST_ERROR_OBJECT (GST_MESSAGE_SRC (msg), "%s (%s)", err->message,
|
||||
(dbg ? dbg : "no details"));
|
||||
g_error_free (err);
|
||||
g_clear_error (&err);
|
||||
g_free (dbg);
|
||||
running = FALSE;
|
||||
break;
|
||||
|
@ -218,6 +218,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", GST_STR_NULL (err->message));
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
return 1;
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
|
|
@ -70,6 +70,7 @@ main (gint argc, gchar ** argv)
|
|||
g_option_context_add_group (opt_ctx, gst_init_get_option_group ());
|
||||
if (!g_option_context_parse (opt_ctx, &argc, &argv, &err))
|
||||
g_error ("Error parsing options: %s", err->message);
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (opt_ctx);
|
||||
|
||||
if (!gst_ptp_init (GST_PTP_CLOCK_ID_NONE, NULL))
|
||||
|
|
|
@ -1499,6 +1499,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_printerr ("Error initializing: %s\n", err->message);
|
||||
g_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
return -1;
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
@ -1615,7 +1617,7 @@ main (int argc, char *argv[])
|
|||
}
|
||||
} else {
|
||||
g_printerr (_("Could not load plugin file: %s\n"), error->message);
|
||||
g_error_free (error);
|
||||
g_clear_error (&error);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -325,7 +325,7 @@ print_error_message (GstMessage * msg)
|
|||
if (debug != NULL)
|
||||
g_printerr (_("Additional debug info:\n%s\n"), debug);
|
||||
|
||||
g_error_free (err);
|
||||
g_clear_error (&err);
|
||||
g_free (debug);
|
||||
g_free (name);
|
||||
}
|
||||
|
@ -649,7 +649,7 @@ event_loop (GstElement * pipeline, gboolean blocking, gboolean do_progress,
|
|||
if (debug) {
|
||||
PRINT (_("INFO:\n%s\n"), debug);
|
||||
}
|
||||
g_error_free (gerror);
|
||||
g_clear_error (&gerror);
|
||||
g_free (debug);
|
||||
g_free (name);
|
||||
break;
|
||||
|
@ -668,7 +668,7 @@ event_loop (GstElement * pipeline, gboolean blocking, gboolean do_progress,
|
|||
if (debug) {
|
||||
PRINT (_("Additional debug info:\n%s\n"), debug);
|
||||
}
|
||||
g_error_free (gerror);
|
||||
g_clear_error (&gerror);
|
||||
g_free (debug);
|
||||
g_free (name);
|
||||
break;
|
||||
|
@ -973,6 +973,8 @@ main (int argc, char *argv[])
|
|||
g_printerr ("Error initializing: %s\n", GST_STR_NULL (err->message));
|
||||
else
|
||||
g_printerr ("Error initializing: Unknown error!\n");
|
||||
g_clear_error (&error);
|
||||
g_option_context_free (ctx);
|
||||
exit (1);
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
@ -1000,7 +1002,7 @@ main (int argc, char *argv[])
|
|||
if (error) {
|
||||
g_printerr (_("ERROR: pipeline could not be constructed: %s.\n"),
|
||||
GST_STR_NULL (error->message));
|
||||
g_error_free (error);
|
||||
g_clear_error (&error);
|
||||
} else {
|
||||
g_printerr (_("ERROR: pipeline could not be constructed.\n"));
|
||||
}
|
||||
|
@ -1008,7 +1010,7 @@ main (int argc, char *argv[])
|
|||
} else if (error) {
|
||||
g_printerr (_("WARNING: erroneous pipeline: %s\n"),
|
||||
GST_STR_NULL (error->message));
|
||||
g_error_free (error);
|
||||
g_clear_error (&error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ typefind_file (const gchar * filename)
|
|||
if (msg) {
|
||||
gst_message_parse_error (msg, &err, NULL);
|
||||
g_printerr ("%s - FAILED: %s\n", filename, err->message);
|
||||
g_error_free (err);
|
||||
g_clear_error (&err);
|
||||
gst_message_unref (msg);
|
||||
} else {
|
||||
g_printerr ("%s - FAILED: unknown error\n", filename);
|
||||
|
@ -162,6 +162,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_clear_error (&err);
|
||||
g_option_context_free (ctx);
|
||||
exit (1);
|
||||
}
|
||||
g_option_context_free (ctx);
|
||||
|
|
Loading…
Reference in a new issue