Commit 78b1212e authored by Olivier Crête's avatar Olivier Crête

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 and soon UDP sockets.

https://phabricator.freedesktop.org/D822
parent 8ef27c6b
......@@ -84,6 +84,9 @@ socket_source_attach (SocketSource *socket_source, GMainContext *context)
{
GSource *source;
if (socket_source->socket->fileno == NULL)
return;
/* Create a source. */
source = g_socket_create_source (socket_source->socket->fileno,
G_IO_IN, NULL);
......@@ -616,9 +619,6 @@ component_attach_socket (Component *component, NiceSocket *nicesock)
g_assert (component->ctx != NULL);
if (nicesock->fileno == NULL)
return;
/* Find an existing SocketSource in the component which contains @socket, or
* create a new one.
*
......@@ -636,7 +636,8 @@ component_attach_socket (Component *component, NiceSocket *nicesock)
socket_source->component = component;
component->socket_sources =
g_slist_prepend (component->socket_sources, socket_source);
component->socket_sources_age++;
if (nicesock->fileno != NULL)
component->socket_sources_age++;
}
/* Create and attach a source */
......@@ -1154,6 +1155,9 @@ component_source_prepare (GSource *source, gint *timeout_)
SocketSource *parent_socket_source = parentl->data;
ChildSocketSource *child_socket_source;
if (parent_socket_source->socket->fileno == NULL)
continue;
/* 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
* 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