Commit bc620c0d authored by Olivier Crête's avatar Olivier Crête Committed by Philip Withnall

component.c: Fix memory leak

If nicesocket is not added to a component it will be leaked.

This is the case of active tcp sockets

Change-Id: I57fefffef71d35ce9871139ee1064181f6fe125b
Reviewed-by: default avatarJosé Antonio Santos Cadenas <santoscadenas@gmail.com>
Differential Revision: https://phabricator.freedesktop.org/D822
parent 38c5e668
...@@ -98,6 +98,9 @@ socket_source_attach (SocketSource *socket_source, GMainContext *context) ...@@ -98,6 +98,9 @@ socket_source_attach (SocketSource *socket_source, GMainContext *context)
{ {
GSource *source; GSource *source;
if (socket_source->socket->fileno == NULL)
return;
/* Create a source. */ /* Create a source. */
source = g_socket_create_source (socket_source->socket->fileno, source = g_socket_create_source (socket_source->socket->fileno,
G_IO_IN, NULL); G_IO_IN, NULL);
...@@ -493,9 +496,6 @@ nice_component_attach_socket (NiceComponent *component, NiceSocket *nicesock) ...@@ -493,9 +496,6 @@ nice_component_attach_socket (NiceComponent *component, NiceSocket *nicesock)
g_assert (component->ctx != NULL); g_assert (component->ctx != NULL);
if (nicesock->fileno == NULL)
return;
/* Find an existing SocketSource in the component which contains @socket, or /* Find an existing SocketSource in the component which contains @socket, or
* create a new one. * create a new one.
* *
...@@ -512,6 +512,7 @@ nice_component_attach_socket (NiceComponent *component, NiceSocket *nicesock) ...@@ -512,6 +512,7 @@ nice_component_attach_socket (NiceComponent *component, NiceSocket *nicesock)
socket_source->component = component; socket_source->component = component;
component->socket_sources = component->socket_sources =
g_slist_prepend (component->socket_sources, socket_source); g_slist_prepend (component->socket_sources, socket_source);
if (nicesock->fileno != NULL)
component->socket_sources_age++; component->socket_sources_age++;
} }
...@@ -1160,6 +1161,9 @@ component_source_prepare (GSource *source, gint *timeout_) ...@@ -1160,6 +1161,9 @@ component_source_prepare (GSource *source, gint *timeout_)
SocketSource *parent_socket_source = parentl->data; SocketSource *parent_socket_source = parentl->data;
SocketSource *child_socket_source; SocketSource *child_socket_source;
if (parent_socket_source->socket->fileno == NULL)
continue;
/* Iterating the list of socket sources every time isn't a big problem /* Iterating the list of socket sources every time isn't a big problem
* because the number of pairs is limited ~100 normally, so there will * because the number of pairs is limited ~100 normally, so there will
* rarely be more than 10. * rarely be more than 10.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment