Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] vinyl: fix leak in vy_build_recover_stmt
@ 2020-10-05 15:33 Kirill Yukhin
  2020-10-05 21:37 ` Nikita Pettik
  0 siblings, 1 reply; 4+ messages in thread
From: Kirill Yukhin @ 2020-10-05 15:33 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Variable `delete` wasn't free()-ed in case of
error. Free it properly.

Found by static analyzer.
---

The patch is intended for all release branches and master.

Branch: https://github.com/tarantool/tarantool/tree/kyukhin/vy-fix-delete-leak
Issue: N/A
CI status: https://gitlab.com/tarantool/tarantool/-/pipelines/198267805

 src/box/vinyl.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index cee39c5..a7ab24d 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -4026,19 +4026,21 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
 		insert = vy_stmt_new_insert(lsm->mem_format,
 					    data, data + data_len);
 		if (insert == NULL)
-			return -1;
+			goto err;
 	} else if (type == IPROTO_UPSERT) {
 		struct tuple *new_tuple = vy_apply_upsert(mem_stmt, old_tuple,
 							  pk->cmp_def, true);
 		if (new_tuple == NULL)
-			return -1;
+			goto err;
 		uint32_t data_len;
 		const char *data = tuple_data_range(new_tuple, &data_len);
 		insert = vy_stmt_new_insert(lsm->mem_format,
 					    data, data + data_len);
 		tuple_unref(new_tuple);
-		if (insert == NULL)
-			return -1;
+		if (insert == NULL) {
+			tuple_unref(new_tuple);
+			goto err;
+		}
 	}
 
 	/* Insert DELETE + INSERT into the LSM tree. */
@@ -4055,6 +4057,11 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
 			return -1;
 	}
 	return 0;
+
+err:
+	if (delete != NULL)
+		tuple_unref(delete);
+	return -1;
 }
 
 /**
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] vinyl: fix leak in vy_build_recover_stmt
  2020-10-05 15:33 [Tarantool-patches] [PATCH] vinyl: fix leak in vy_build_recover_stmt Kirill Yukhin
@ 2020-10-05 21:37 ` Nikita Pettik
  2020-10-06  4:13   ` Kirill Yukhin
  0 siblings, 1 reply; 4+ messages in thread
From: Nikita Pettik @ 2020-10-05 21:37 UTC (permalink / raw)
  To: Kirill Yukhin; +Cc: tarantool-patches

On 05 Oct 18:33, Kirill Yukhin wrote:
> Variable `delete` wasn't free()-ed in case of
> error. Free it properly.
> 
> Found by static analyzer.
> ---
> 
> The patch is intended for all release branches and master.
> 
> Branch: https://github.com/tarantool/tarantool/tree/kyukhin/vy-fix-delete-leak
> Issue: N/A
> CI status: https://gitlab.com/tarantool/tarantool/-/pipelines/198267805
> 
>  src/box/vinyl.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/src/box/vinyl.c b/src/box/vinyl.c
> index cee39c5..a7ab24d 100644
> --- a/src/box/vinyl.c
> +++ b/src/box/vinyl.c
> @@ -4026,19 +4026,21 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
>  		insert = vy_stmt_new_insert(lsm->mem_format,
>  					    data, data + data_len);
>  		if (insert == NULL)
> -			return -1;
> +			goto err;
>  	} else if (type == IPROTO_UPSERT) {
>  		struct tuple *new_tuple = vy_apply_upsert(mem_stmt, old_tuple,
>  							  pk->cmp_def, true);
>  		if (new_tuple == NULL)
> -			return -1;
> +			goto err;
>  		uint32_t data_len;
>  		const char *data = tuple_data_range(new_tuple, &data_len);
>  		insert = vy_stmt_new_insert(lsm->mem_format,
>  					    data, data + data_len);
>  		tuple_unref(new_tuple);
> -		if (insert == NULL)
> -			return -1;
> +		if (insert == NULL) {
> +			tuple_unref(new_tuple);

new_tuple is unrefed one line above unconditionally.

> +			goto err;
> +		}
>  	}
>  
>  	/* Insert DELETE + INSERT into the LSM tree. */
> @@ -4055,6 +4057,11 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
>  			return -1;
>  	}
>  	return 0;
> +
> +err:
> +	if (delete != NULL)
> +		tuple_unref(delete);
> +	return -1;
>  }
>  
>  /**
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] vinyl: fix leak in vy_build_recover_stmt
  2020-10-05 21:37 ` Nikita Pettik
@ 2020-10-06  4:13   ` Kirill Yukhin
  2020-10-06 13:33     ` Nikita Pettik
  0 siblings, 1 reply; 4+ messages in thread
From: Kirill Yukhin @ 2020-10-06  4:13 UTC (permalink / raw)
  To: Nikita Pettik; +Cc: tarantool-patches

Hello,

On 05 окт 21:37, Nikita Pettik wrote:
> On 05 Oct 18:33, Kirill Yukhin wrote:
> > diff --git a/src/box/vinyl.c b/src/box/vinyl.c
> > index cee39c5..a7ab24d 100644
> > --- a/src/box/vinyl.c
> > +++ b/src/box/vinyl.c
> > @@ -4026,19 +4026,21 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
> >  		insert = vy_stmt_new_insert(lsm->mem_format,
> >  					    data, data + data_len);
> >  		if (insert == NULL)
> > -			return -1;
> > +			goto err;
> >  	} else if (type == IPROTO_UPSERT) {
> >  		struct tuple *new_tuple = vy_apply_upsert(mem_stmt, old_tuple,
> >  							  pk->cmp_def, true);
> >  		if (new_tuple == NULL)
> > -			return -1;
> > +			goto err;
> >  		uint32_t data_len;
> >  		const char *data = tuple_data_range(new_tuple, &data_len);
> >  		insert = vy_stmt_new_insert(lsm->mem_format,
> >  					    data, data + data_len);
> >  		tuple_unref(new_tuple);
> > -		if (insert == NULL)
> > -			return -1;
> > +		if (insert == NULL) {
> > +			tuple_unref(new_tuple);
> 
> new_tuple is unrefed one line above unconditionally.

Thanks, removed. Iterative patch in the bottom.
Branch force-pushed.

--
Regards, Kirill Yukhin

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index a7ab24d..7e56299 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -4037,10 +4037,8 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
 		insert = vy_stmt_new_insert(lsm->mem_format,
 					    data, data + data_len);
 		tuple_unref(new_tuple);
-		if (insert == NULL) {
-			tuple_unref(new_tuple);
+		if (insert == NULL)
 			goto err;
-		}
 	}
 
 	/* Insert DELETE + INSERT into the LSM tree. */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] vinyl: fix leak in vy_build_recover_stmt
  2020-10-06  4:13   ` Kirill Yukhin
@ 2020-10-06 13:33     ` Nikita Pettik
  0 siblings, 0 replies; 4+ messages in thread
From: Nikita Pettik @ 2020-10-06 13:33 UTC (permalink / raw)
  To: Kirill Yukhin; +Cc: tarantool-patches

On 06 Oct 07:13, Kirill Yukhin wrote:
> Hello,
> 
> On 05 окт 21:37, Nikita Pettik wrote:
> > On 05 Oct 18:33, Kirill Yukhin wrote:
> > > diff --git a/src/box/vinyl.c b/src/box/vinyl.c
> > > index cee39c5..a7ab24d 100644
> > > --- a/src/box/vinyl.c
> > > +++ b/src/box/vinyl.c
> > > @@ -4026,19 +4026,21 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
> > >  		insert = vy_stmt_new_insert(lsm->mem_format,
> > >  					    data, data + data_len);
> > >  		if (insert == NULL)
> > > -			return -1;
> > > +			goto err;
> > >  	} else if (type == IPROTO_UPSERT) {
> > >  		struct tuple *new_tuple = vy_apply_upsert(mem_stmt, old_tuple,
> > >  							  pk->cmp_def, true);
> > >  		if (new_tuple == NULL)
> > > -			return -1;
> > > +			goto err;
> > >  		uint32_t data_len;
> > >  		const char *data = tuple_data_range(new_tuple, &data_len);
> > >  		insert = vy_stmt_new_insert(lsm->mem_format,
> > >  					    data, data + data_len);
> > >  		tuple_unref(new_tuple);
> > > -		if (insert == NULL)
> > > -			return -1;
> > > +		if (insert == NULL) {
> > > +			tuple_unref(new_tuple);
> > 
> > new_tuple is unrefed one line above unconditionally.
> 
> Thanks, removed. Iterative patch in the bottom.
> Branch force-pushed.

Pushed to master, 2.5, 2.4 and 1.10. Branch is dropped.
 
> --
> Regards, Kirill Yukhin
> 
> diff --git a/src/box/vinyl.c b/src/box/vinyl.c
> index a7ab24d..7e56299 100644
> --- a/src/box/vinyl.c
> +++ b/src/box/vinyl.c
> @@ -4037,10 +4037,8 @@ vy_build_recover_stmt(struct vy_lsm *lsm, struct vy_lsm *pk,
>  		insert = vy_stmt_new_insert(lsm->mem_format,
>  					    data, data + data_len);
>  		tuple_unref(new_tuple);
> -		if (insert == NULL) {
> -			tuple_unref(new_tuple);
> +		if (insert == NULL)
>  			goto err;
> -		}
>  	}
>  
>  	/* Insert DELETE + INSERT into the LSM tree. */

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-06 13:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 15:33 [Tarantool-patches] [PATCH] vinyl: fix leak in vy_build_recover_stmt Kirill Yukhin
2020-10-05 21:37 ` Nikita Pettik
2020-10-06  4:13   ` Kirill Yukhin
2020-10-06 13:33     ` Nikita Pettik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox