[lttng-dev] [PATCH lttng-tools] Fix: FD leak in accept error handling

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Sat Oct 4 09:24:02 EDT 2014


Bump.

----- Original Message -----
> From: "Mathieu Desnoyers" <mathieu.desnoyers at efficios.com>
> To: dgoulet at efficios.com
> Cc: lttng-dev at lists.lttng.org, "Mathieu Desnoyers" <mathieu.desnoyers at efficios.com>
> Sent: Saturday, September 27, 2014 7:49:22 PM
> Subject: [PATCH lttng-tools] Fix: FD leak in accept error handling
> 
> *** CID 1241799:  Resource leak  (RESOURCE_LEAK)
> /src/common/sessiond-comm/inet.c: 324 in lttcomm_accept_inet_sock()
> 318
> 319     end:
> 320             return new_sock;
> 321
> 322     error:
> 323             free(new_sock);
> >>>     CID 1241799:  Resource leak  (RESOURCE_LEAK)
> >>>     Handle variable "new_fd" going out of scope leaks the handle.
> 324             return NULL;
> 325     }
> 326
> 327     /*
> 328      * Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN.
> 329      */
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> ---
>  src/common/sessiond-comm/inet.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/src/common/sessiond-comm/inet.c
> b/src/common/sessiond-comm/inet.c
> index cf06ecb..4e34ad0 100644
> --- a/src/common/sessiond-comm/inet.c
> +++ b/src/common/sessiond-comm/inet.c
> @@ -272,7 +272,7 @@ error_connect:
>  LTTNG_HIDDEN
>  struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock)
>  {
> -	int new_fd;
> +	int new_fd, closeret;
>  	socklen_t len;
>  	struct lttcomm_sock *new_sock;
>  	unsigned long timeout;
> @@ -305,10 +305,18 @@ struct lttcomm_sock *lttcomm_accept_inet_sock(struct
> lttcomm_sock *sock)
>  
>  		ret = lttcomm_setsockopt_rcv_timeout(new_fd, timeout);
>  		if (ret) {
> +			closeret = close(new_fd);
> +			if (closeret) {
> +				PERROR("close");
> +			}
>  			goto error;
>  		}
>  		ret = lttcomm_setsockopt_snd_timeout(new_fd, timeout);
>  		if (ret) {
> +			closeret = close(new_fd);
> +			if (closeret) {
> +				PERROR("close");
> +			}
>  			goto error;
>  		}
>  	}
> --
> 2.1.0
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list