Commit c41021da authored by Youness Alaoui's avatar Youness Alaoui

Fix memory leak with udp-bsd

parent 26262bb7
...@@ -67,10 +67,9 @@ NiceSocket * ...@@ -67,10 +67,9 @@ NiceSocket *
nice_udp_bsd_socket_new (NiceAddress *addr) nice_udp_bsd_socket_new (NiceAddress *addr)
{ {
struct sockaddr_storage name; struct sockaddr_storage name;
socklen_t name_len = sizeof (name);
NiceSocket *sock = g_slice_new0 (NiceSocket); NiceSocket *sock = g_slice_new0 (NiceSocket);
GSocket *gsock = NULL; GSocket *gsock = NULL;
gboolean gret; gboolean gret = FALSE;
GSocketAddress *gaddr; GSocketAddress *gaddr;
if (addr != NULL) { if (addr != NULL) {
...@@ -100,13 +99,15 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -100,13 +99,15 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
return NULL; return NULL;
} }
/* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking(gsock, false);
name_len = name.ss_family == AF_INET? sizeof (struct sockaddr_in) : /* GSocket: All socket file descriptors are set to be close-on-exec. */
sizeof(struct sockaddr_in6); g_socket_set_blocking (gsock, false);
gaddr = g_socket_address_new_from_native (&name, sizeof (name));
if (gaddr != NULL) {
gret = g_socket_bind (gsock, gaddr, FALSE, NULL);
g_object_unref (gaddr);
}
gret = g_socket_bind(gsock, g_socket_address_new_from_native(&name, name_len), FALSE, NULL);
if (gret == FALSE) { if (gret == FALSE) {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
g_socket_close (gsock, NULL); g_socket_close (gsock, NULL);
...@@ -114,16 +115,16 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -114,16 +115,16 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
return NULL; return NULL;
} }
gaddr = g_socket_get_local_address(gsock, NULL); gaddr = g_socket_get_local_address (gsock, NULL);
if(gaddr == NULL) { if (gaddr == NULL ||
!g_socket_address_to_native (gaddr, &name, sizeof(name), NULL)) {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
g_socket_close (gsock, NULL); g_socket_close (gsock, NULL);
g_object_unref (gsock); g_object_unref (gsock);
return NULL; return NULL;
} }
g_socket_address_to_native(gaddr, &name, name_len, NULL); g_object_unref (gaddr);
g_object_unref(gaddr);
nice_address_set_from_sockaddr (&sock->addr, (struct sockaddr *)&name); nice_address_set_from_sockaddr (&sock->addr, (struct sockaddr *)&name);
......
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