Re: [gnet-dev] gnet_udp_socket_new_interface memory leak



Fixed.  Thanks.

David


On Thu, 18 Jul 2002, Jakub Jagielka wrote:

> 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;
> }
>
>
> _______________________________________________
> gnet-dev mailing list
> gnet-dev gnetlibrary org
> http://www.gnetlibrary.org/mailman/listinfo/gnet-dev
>

-- 
      __          _    __ David Helder - dhelder umich edu
  ___/ /__ __  __(_)__/ / <http://www.eecs.umich.edu/~dhelder>
 / _  / _ `/ |/ / / _  /  Jungle Monkey: <http://www.junglemonkey.net>
 |_,_/|_,_/|___/_/|_,_/   Paper CD Case: <http://www.papercdcase.com>




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