From c41021da1598694714d058a3427c8bb0755ff769 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Thu, 1 Mar 2012 21:31:52 -0500 Subject: [PATCH] Fix memory leak with udp-bsd --- socket/udp-bsd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/socket/udp-bsd.c b/socket/udp-bsd.c index 9f5a956..c949d68 100644 --- a/socket/udp-bsd.c +++ b/socket/udp-bsd.c @@ -67,10 +67,9 @@ NiceSocket * nice_udp_bsd_socket_new (NiceAddress *addr) { struct sockaddr_storage name; - socklen_t name_len = sizeof (name); NiceSocket *sock = g_slice_new0 (NiceSocket); GSocket *gsock = NULL; - gboolean gret; + gboolean gret = FALSE; GSocketAddress *gaddr; if (addr != NULL) { @@ -100,13 +99,15 @@ nice_udp_bsd_socket_new (NiceAddress *addr) g_slice_free (NiceSocket, sock); 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) : - sizeof(struct sockaddr_in6); + /* GSocket: All socket file descriptors are set to be close-on-exec. */ + 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) { g_slice_free (NiceSocket, sock); g_socket_close (gsock, NULL); @@ -114,16 +115,16 @@ nice_udp_bsd_socket_new (NiceAddress *addr) return NULL; } - gaddr = g_socket_get_local_address(gsock, NULL); - if(gaddr == NULL) { + gaddr = g_socket_get_local_address (gsock, NULL); + if (gaddr == NULL || + !g_socket_address_to_native (gaddr, &name, sizeof(name), NULL)) { g_slice_free (NiceSocket, sock); g_socket_close (gsock, NULL); g_object_unref (gsock); 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); -- 2.11.4.GIT