Re: [PATCHv4 3/4] bundle: don't leak an fd in case of early return

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

 



On Fri, Apr 01, 2016 at 10:29:51AM -0700, Junio C Hamano wrote:

> > This does still suffer from the double-close I mentioned earlier. I'm
> > not sure if we want to address that or not.
> 
> Something like this on top?
> 
>  bundle.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/bundle.c b/bundle.c
> index 08e32ca..bbf4efa 100644
> --- a/bundle.c
> +++ b/bundle.c
> @@ -453,8 +453,10 @@ int create_bundle(struct bundle_header *header, const char *path,
>  		goto err;
>  
>  	/* write pack */
> -	if (write_pack_data(bundle_fd, &revs))
> +	if (write_pack_data(bundle_fd, &revs)) {
> +		bundle_fd = -1; /* already closed by the above call */
>  		goto err;
> +	}
>  
>  	if (!bundle_to_stdout) {
>  		if (commit_lock_file(&lock))
> @@ -463,7 +465,8 @@ int create_bundle(struct bundle_header *header, const char *path,
>  	return 0;
>  err:
>  	if (!bundle_to_stdout) {
> -		close(bundle_fd);
> +		if (0 <= bundle_fd)
> +			close(bundle_fd);
>  		rollback_lock_file(&lock);

Yep, that looks fine.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]