[gnet-dev] gnet_udp_socket_new_interface memory leak



Hi,

While scanning source code of gnet 1.1.4, I found the memory leak in gnet_udp_socket_new_interface.
With any error function returns without freeing newly created GUdpSocket.

What is interesting in gnet_tcp_socket_new_direct the memory is safe.

Regards,
Jakub Jagielka


GUdpSocket*
gnet_udp_socket_new_interface (const GInetAddr* iface)
{
 GUdpSocket* s;
 const int on = 1;

 g_return_val_if_fail (iface, NULL);

 /* Create socket */
 s = g_new0 (GUdpSocket, 1);
 s->ref_count = 1;
 s->sockfd = socket(AF_INET, SOCK_DGRAM, 0);
 if (s->sockfd < 0)
   return NULL;

 /* Set broadcast option.  This allows the user to broadcast packets.
    It has not affect otherwise. */
 if (setsockopt(s->sockfd, SOL_SOCKET, SO_BROADCAST,
        (void*) &on, sizeof(on)) != 0)
   {
     GNET_CLOSE_SOCKET(s->sockfd);
     return NULL;
   }

 /* Bind to the socket to some local address and port */
 if (bind(s->sockfd, &iface->sa, sizeof(iface->sa)) != 0)
   return NULL;

 return s;
}





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]