[Ocfs2-tools-devel] [PATCH] libocfs2: close fd if read fails in create_generation

Junxiao Bi junxiao.bi at oracle.com
Sun Jul 17 18:50:18 PDT 2016


On 07/16/2016 12:01 PM, Joseph Qi wrote:
> Currently fd is leaked if read fails in create_generation, so fix it.
Looks good.

Reviewed-by: Junxiao Bi <junxiao.bi at oracle.com>
> 
> Signed-off-by: Joseph Qi <joseph.qi at huawei.com>
> ---
>  libocfs2/refcount.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libocfs2/refcount.c b/libocfs2/refcount.c
> index 6afe032..bb23530 100644
> --- a/libocfs2/refcount.c
> +++ b/libocfs2/refcount.c
> @@ -2138,8 +2138,10 @@ static errcode_t create_generation(uint32_t *value)
>  	if (randfd < 0)
>  		return errno;
> 
> -	if (read(randfd, value, readlen) != readlen)
> +	if (read(randfd, value, readlen) != readlen) {
> +		close(randfd);
>  		return errno;
> +	}
> 
>  	close(randfd);
> 




More information about the Ocfs2-tools-devel mailing list