Commit beea9b38 authored by Olivier Crête's avatar Olivier Crête

tcp-passive: Clear connection on child closing

If this isn't done, then there may be invalid points left inside the
passive socket which could be used and cause a crash.

Fixes #33
parent a05e9dcf
Pipeline #11590 passed with stage
in 1 minute and 28 seconds
......@@ -46,6 +46,8 @@
#include "agent-priv.h"
#include "socket-priv.h"
#include "tcp-passive.h"
#include <string.h>
#include <errno.h>
#include <fcntl.h>
......@@ -70,6 +72,7 @@ typedef struct {
gboolean reliable;
NiceSocketWritableCb writable_cb;
gpointer writable_data;
NiceSocket *passive_parent;
} TcpPriv;
#define MAX_QUEUE_LENGTH 20
......@@ -226,6 +229,10 @@ socket_close (NiceSocket *sock)
g_source_unref (priv->io_source);
}
if (priv->passive_parent) {
nice_tcp_passive_socket_remove_connection (priv->passive_parent, &priv->remote_addr);
}
nice_socket_free_send_queue (&priv->send_queue);
if (priv->context)
......@@ -458,3 +465,13 @@ socket_send_more (
g_mutex_unlock (&mutex);
return TRUE;
}
void
nice_tcp_bsd_socket_set_passive_parent (NiceSocket *sock, NiceSocket *passive_parent)
{
TcpPriv *priv = sock->priv;
g_assert (priv->passive_parent == NULL);
priv->passive_parent = passive_parent;
}
......@@ -49,6 +49,9 @@ NiceSocket *
nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
NiceAddress *remote_addr, NiceAddress *local_addr, gboolean reliable);
void
nice_tcp_bsd_socket_set_passive_parent (NiceSocket *socket, NiceSocket *passive_parent);
G_END_DECLS
#endif /* _TCP_BSD_H */
......
......@@ -310,6 +310,8 @@ nice_tcp_passive_socket_accept (NiceSocket *sock)
if (new_socket) {
NiceAddress *key = nice_address_dup (&remote_addr);
nice_tcp_bsd_socket_set_passive_parent (new_socket, sock);
nice_socket_set_writable_callback (new_socket, _child_writable_cb, sock);
g_hash_table_insert (priv->connections, key, new_socket);
}
......@@ -329,3 +331,10 @@ static guint nice_address_hash (const NiceAddress * key)
return hash;
}
void nice_tcp_passive_socket_remove_connection (NiceSocket *sock, const NiceAddress *to)
{
TcpPassivePriv *priv = sock->priv;
g_hash_table_remove (priv->connections, to);
}
......@@ -46,6 +46,9 @@ G_BEGIN_DECLS
NiceSocket * nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr);
NiceSocket * nice_tcp_passive_socket_accept (NiceSocket *socket);
void nice_tcp_passive_socket_remove_connection (NiceSocket *socket,
const NiceAddress *to);
G_END_DECLS
......
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