From c2438ba86839dbdbc2dc7b8224feebeeb1631bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 17 Jan 2012 11:32:01 +0100 Subject: [PATCH] tcp: Don't leak the resolver if name resolval failed --- gst/tcp/gsttcpclientsink.c | 5 ++++- gst/tcp/gsttcpclientsrc.c | 5 ++++- gst/tcp/gsttcpserversink.c | 5 ++++- gst/tcp/gsttcpserversrc.c | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gst/tcp/gsttcpclientsink.c b/gst/tcp/gsttcpclientsink.c index 9ce50c484d..7a9c513b4e 100644 --- a/gst/tcp/gsttcpclientsink.c +++ b/gst/tcp/gsttcpclientsink.c @@ -282,6 +282,7 @@ gst_tcp_client_sink_start (GstBaseSink * bsink) GError *err = NULL; GInetAddress *addr; GSocketAddress *saddr; + GResolver *resolver; if (GST_OBJECT_FLAG_IS_SET (this, GST_TCP_CLIENT_SINK_OPEN)) return TRUE; @@ -300,9 +301,10 @@ gst_tcp_client_sink_start (GstBaseSink * bsink) /* look up name if we need to */ addr = g_inet_address_new_from_string (this->host); if (!addr) { - GResolver *resolver = g_resolver_get_default (); GList *results; + resolver = g_resolver_get_default (); + results = g_resolver_lookup_by_name (resolver, this->host, this->cancellable, &err); @@ -351,6 +353,7 @@ name_resolve: ("Failed to resolve host '%s': %s", this->host, err->message)); } g_clear_error (&err); + g_object_unref (resolver); gst_tcp_client_sink_stop (GST_BASE_SINK (this)); return FALSE; } diff --git a/gst/tcp/gsttcpclientsrc.c b/gst/tcp/gsttcpclientsrc.c index d761876d41..f8ed6b963a 100644 --- a/gst/tcp/gsttcpclientsrc.c +++ b/gst/tcp/gsttcpclientsrc.c @@ -289,6 +289,7 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc) GError *err = NULL; GInetAddress *addr; GSocketAddress *saddr; + GResolver *resolver; /* create receiving client socket */ GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d", @@ -306,9 +307,10 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc) /* look up name if we need to */ addr = g_inet_address_new_from_string (src->host); if (!addr) { - GResolver *resolver = g_resolver_get_default (); GList *results; + resolver = g_resolver_get_default (); + results = g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err); if (!results) @@ -353,6 +355,7 @@ name_resolve: ("Failed to resolve host '%s': %s", src->host, err->message)); } g_clear_error (&err); + g_object_unref (resolver); gst_tcp_client_src_stop (GST_BASE_SRC (src)); return FALSE; } diff --git a/gst/tcp/gsttcpserversink.c b/gst/tcp/gsttcpserversink.c index b3df834685..f7b0023bca 100644 --- a/gst/tcp/gsttcpserversink.c +++ b/gst/tcp/gsttcpserversink.c @@ -271,6 +271,7 @@ gst_tcp_server_sink_init_send (GstMultiSocketSink * parent) GError *err = NULL; GInetAddress *addr; GSocketAddress *saddr; + GResolver *resolver; /* create the server listener socket */ this->server_socket = @@ -285,9 +286,10 @@ gst_tcp_server_sink_init_send (GstMultiSocketSink * parent) /* look up name if we need to */ addr = g_inet_address_new_from_string (this->host); if (!addr) { - GResolver *resolver = g_resolver_get_default (); GList *results; + resolver = g_resolver_get_default (); + results = g_resolver_lookup_by_name (resolver, this->host, this->element.cancellable, &err); @@ -353,6 +355,7 @@ name_resolve: ("Failed to resolve host '%s': %s", this->host, err->message)); } g_clear_error (&err); + g_object_unref (resolver); gst_tcp_server_sink_close (&this->element); return FALSE; } diff --git a/gst/tcp/gsttcpserversrc.c b/gst/tcp/gsttcpserversrc.c index 42a89ed703..0cdfdd2be5 100644 --- a/gst/tcp/gsttcpserversrc.c +++ b/gst/tcp/gsttcpserversrc.c @@ -295,6 +295,7 @@ gst_tcp_server_src_start (GstBaseSrc * bsrc) GError *err = NULL; GInetAddress *addr; GSocketAddress *saddr; + GResolver *resolver; /* create the server listener socket */ src->server_socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, @@ -307,9 +308,10 @@ gst_tcp_server_src_start (GstBaseSrc * bsrc) /* look up name if we need to */ addr = g_inet_address_new_from_string (src->host); if (!addr) { - GResolver *resolver = g_resolver_get_default (); GList *results; + resolver = g_resolver_get_default (); + results = g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err); if (!results) @@ -362,6 +364,7 @@ name_resolve: ("Failed to resolve host '%s': %s", src->host, err->message)); } g_clear_error (&err); + g_object_unref (resolver); gst_tcp_server_src_stop (GST_BASE_SRC (src)); return FALSE; }