Re: [PATCH 1/2] btrfs-progs: add necessary close(fd) in mkfs

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

 




On 18.08.2017 11:32, Gu Jinxiang wrote:
> Add some close(fd) when error occures in mkfs.
> And add close(fd) when end use it.

When a process exits all of its fds (and all other runtime resources
tracked by the kernel) are freed, so we don't leak fds if that's your
worry. Admittedly, it's good practice to manage the lifetime of fds
correctly in a program, so I don't have any strong preferences either ways.


> 
> Signed-off-by: Gu Jinxiang <gujx@xxxxxxxxxxxxxx>
> ---
>  mkfs/main.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 2b109a5..ec82565 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -1694,6 +1694,7 @@ int main(int argc, char **argv)
>  					file,
>  					(unsigned long long)block_count,
>  					(unsigned long long)dev_block_count);
> +			close(fd);
>  			exit(1);
>  		}
>  	} else {
> @@ -1711,6 +1712,7 @@ int main(int argc, char **argv)
>  		ret = zero_output_file(fd, block_count);
>  		if (ret) {
>  			error("unable to zero the output file");
> +			close(fd);
>  			exit(1);
>  		}
>  		/* our "device" is the new image file */
> @@ -1721,6 +1723,7 @@ int main(int argc, char **argv)
>  	if (dev_block_count < BTRFS_MKFS_SYSTEM_GROUP_SIZE) {
>  		error("device is too small to make filesystem, must be at least %llu",
>  				(unsigned long long)BTRFS_MKFS_SYSTEM_GROUP_SIZE);
> +		close(fd);
>  		exit(1);
>  	}
>  
> @@ -1740,6 +1743,7 @@ int main(int argc, char **argv)
>  	ret = make_btrfs(fd, &mkfs_cfg);
>  	if (ret) {
>  		error("error during mkfs: %s", strerror(-ret));
> +		close(fd);
>  		exit(1);
>  	}
>  
> @@ -1750,6 +1754,7 @@ int main(int argc, char **argv)
>  		close(fd);
>  		exit(1);
>  	}
> +	close(fd);
>  	root = fs_info->fs_root;
>  	fs_info->alloc_start = alloc_start;
>  
> @@ -1827,6 +1832,7 @@ int main(int argc, char **argv)
>  					sectorsize, sectorsize, sectorsize);
>  		if (ret) {
>  			error("unable to add %s to filesystem: %d", file, ret);
> +			close(fd);
>  			goto out;
>  		}
>  		if (verbose >= 2) {
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux