[PATCH] gdhcp: Fix resource leak

Marcel Holtmann marcel at holtmann.org
Fri Nov 9 00:07:15 PST 2012


Hi Danny,

> The socket was not closed when the sendto got failed.
> ---
>  gdhcp/ipv4ll.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c
> index 17ab3d5..283bb9b 100644
> --- a/gdhcp/ipv4ll.c
> +++ b/gdhcp/ipv4ll.c
> @@ -110,11 +110,12 @@ int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t source_ip,
>  
>  	n = sendto(fd, &p, sizeof(p), 0,
>  	       (struct sockaddr*) &dest, sizeof(dest));
> -	if (n < 0)
> -		return -errno;
>  
>  	close(fd);
>  
> +	if (n < 0)
> +		return -errno;
> +

you need to store errno first. It is is not guaranteed the one from
sendto anymore. Could now be also from close.

Regards

Marcel





More information about the connman mailing list