tcp: Don't leak the resolver if name resolval failed

This commit is contained in:
Sebastian Dröge 2012-01-17 11:32:01 +01:00
parent f98e647a31
commit c2438ba868
4 changed files with 16 additions and 4 deletions

View file

@ -282,6 +282,7 @@ gst_tcp_client_sink_start (GstBaseSink * bsink)
GError *err = NULL; GError *err = NULL;
GInetAddress *addr; GInetAddress *addr;
GSocketAddress *saddr; GSocketAddress *saddr;
GResolver *resolver;
if (GST_OBJECT_FLAG_IS_SET (this, GST_TCP_CLIENT_SINK_OPEN)) if (GST_OBJECT_FLAG_IS_SET (this, GST_TCP_CLIENT_SINK_OPEN))
return TRUE; return TRUE;
@ -300,9 +301,10 @@ gst_tcp_client_sink_start (GstBaseSink * bsink)
/* look up name if we need to */ /* look up name if we need to */
addr = g_inet_address_new_from_string (this->host); addr = g_inet_address_new_from_string (this->host);
if (!addr) { if (!addr) {
GResolver *resolver = g_resolver_get_default ();
GList *results; GList *results;
resolver = g_resolver_get_default ();
results = results =
g_resolver_lookup_by_name (resolver, this->host, this->cancellable, g_resolver_lookup_by_name (resolver, this->host, this->cancellable,
&err); &err);
@ -351,6 +353,7 @@ name_resolve:
("Failed to resolve host '%s': %s", this->host, err->message)); ("Failed to resolve host '%s': %s", this->host, err->message));
} }
g_clear_error (&err); g_clear_error (&err);
g_object_unref (resolver);
gst_tcp_client_sink_stop (GST_BASE_SINK (this)); gst_tcp_client_sink_stop (GST_BASE_SINK (this));
return FALSE; return FALSE;
} }

View file

@ -289,6 +289,7 @@ gst_tcp_client_src_start (GstBaseSrc * bsrc)
GError *err = NULL; GError *err = NULL;
GInetAddress *addr; GInetAddress *addr;
GSocketAddress *saddr; GSocketAddress *saddr;
GResolver *resolver;
/* create receiving client socket */ /* create receiving client socket */
GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d", 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 */ /* look up name if we need to */
addr = g_inet_address_new_from_string (src->host); addr = g_inet_address_new_from_string (src->host);
if (!addr) { if (!addr) {
GResolver *resolver = g_resolver_get_default ();
GList *results; GList *results;
resolver = g_resolver_get_default ();
results = results =
g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err); g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err);
if (!results) if (!results)
@ -353,6 +355,7 @@ name_resolve:
("Failed to resolve host '%s': %s", src->host, err->message)); ("Failed to resolve host '%s': %s", src->host, err->message));
} }
g_clear_error (&err); g_clear_error (&err);
g_object_unref (resolver);
gst_tcp_client_src_stop (GST_BASE_SRC (src)); gst_tcp_client_src_stop (GST_BASE_SRC (src));
return FALSE; return FALSE;
} }

View file

@ -271,6 +271,7 @@ gst_tcp_server_sink_init_send (GstMultiSocketSink * parent)
GError *err = NULL; GError *err = NULL;
GInetAddress *addr; GInetAddress *addr;
GSocketAddress *saddr; GSocketAddress *saddr;
GResolver *resolver;
/* create the server listener socket */ /* create the server listener socket */
this->server_socket = this->server_socket =
@ -285,9 +286,10 @@ gst_tcp_server_sink_init_send (GstMultiSocketSink * parent)
/* look up name if we need to */ /* look up name if we need to */
addr = g_inet_address_new_from_string (this->host); addr = g_inet_address_new_from_string (this->host);
if (!addr) { if (!addr) {
GResolver *resolver = g_resolver_get_default ();
GList *results; GList *results;
resolver = g_resolver_get_default ();
results = results =
g_resolver_lookup_by_name (resolver, this->host, g_resolver_lookup_by_name (resolver, this->host,
this->element.cancellable, &err); this->element.cancellable, &err);
@ -353,6 +355,7 @@ name_resolve:
("Failed to resolve host '%s': %s", this->host, err->message)); ("Failed to resolve host '%s': %s", this->host, err->message));
} }
g_clear_error (&err); g_clear_error (&err);
g_object_unref (resolver);
gst_tcp_server_sink_close (&this->element); gst_tcp_server_sink_close (&this->element);
return FALSE; return FALSE;
} }

View file

@ -295,6 +295,7 @@ gst_tcp_server_src_start (GstBaseSrc * bsrc)
GError *err = NULL; GError *err = NULL;
GInetAddress *addr; GInetAddress *addr;
GSocketAddress *saddr; GSocketAddress *saddr;
GResolver *resolver;
/* create the server listener socket */ /* create the server listener socket */
src->server_socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, 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 */ /* look up name if we need to */
addr = g_inet_address_new_from_string (src->host); addr = g_inet_address_new_from_string (src->host);
if (!addr) { if (!addr) {
GResolver *resolver = g_resolver_get_default ();
GList *results; GList *results;
resolver = g_resolver_get_default ();
results = results =
g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err); g_resolver_lookup_by_name (resolver, src->host, src->cancellable, &err);
if (!results) if (!results)
@ -362,6 +364,7 @@ name_resolve:
("Failed to resolve host '%s': %s", src->host, err->message)); ("Failed to resolve host '%s': %s", src->host, err->message));
} }
g_clear_error (&err); g_clear_error (&err);
g_object_unref (resolver);
gst_tcp_server_src_stop (GST_BASE_SRC (src)); gst_tcp_server_src_stop (GST_BASE_SRC (src));
return FALSE; return FALSE;
} }