[Devel] [PATCH 1/1] Drivers: md: ploop - Do not leak a page on allocation failure

Vasily Averin vvs at openvz.org
Wed Jul 20 20:57:13 MSK 2022


Hi Alexander!

On 7/20/22 14:05, Alexander Atanasov wrote:
> Fix off-by-one error - tries to free the failed allocation and
> it leaks the first successful

Could you please elaborate? I do not see the difference in behavior.

if we have failed on 2nd allocation
we have i = 1
io_vec[0] was set 
io_vec[1] was failed
we jump to err: label
doing i-- end call put_page for io_vec[0]
2nd turn fails.
So looks like all works correctly.
With your patch situation is not changed.

Am I missed something perhaps?

Thank you,
	Vasily Averin

> Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
> ---
>  drivers/md/dm-ploop-cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
> index 429a03cce392..e4ea738828bc 100644
> --- a/drivers/md/dm-ploop-cmd.c
> +++ b/drivers/md/dm-ploop-cmd.c
> @@ -489,7 +489,7 @@ struct pio *alloc_pio_with_pages(struct ploop *ploop)
>  
>  	return pio;
>  err:
> -	while (i-- > 0)
> +	while (--i >= 0)
>  		put_page(pio->bi_io_vec[i].bv_page);
>  	kfree(pio);
>  	return NULL;



More information about the Devel mailing list