Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev <imeevma@tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@freelists.org, tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/1] netbox: fix memleak in lbox_tuple_format_new()
Date: Thu, 31 Oct 2019 12:33:26 +0300	[thread overview]
Message-ID: <20191031093326.GA3276@tarantool.org> (raw)
In-Reply-To: <0dd15716-6130-3dc3-5019-c2228681ba08@tarantool.org>

Thank you for review. I fixed the error and reworked the
patch a bit. New patch below.

On Wed, Oct 30, 2019 at 11:13:54PM +0100, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
> 
> On 30/10/2019 11:58, imeevma@tarantool.org wrote:
> > Memleak appeared due to the fact that when creating a dictionary
> > its reference count is 1 from the beginning. Later, when the
> > dictionary is used to create tuple_format, its reference counter
> > increased by 1 and it became equal to 2. After removing
> > tuple_format, the reference counter for dict decreased by one, so
> > it became equal to 1. Since ref counter is not equal to 0, dict
> > not deleted, causing a memory leak.
> > 
> > Closes #4588
> > ---
> >  src/box/lua/misc.cc | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/src/box/lua/misc.cc b/src/box/lua/misc.cc
> > index 7b8b9dc..102194e 100644
> > --- a/src/box/lua/misc.cc
> > +++ b/src/box/lua/misc.cc
> > @@ -233,6 +233,7 @@ lbox_tuple_format_new(struct lua_State *L)
> >  				 NULL, 0, 0, dict, false, false);
> >  	if (format == NULL)
> >  		return luaT_error(L);
> 
> The dict should be unreferenced regardless of tuple_format_new()
> result. Now there is a leak, when format == NULL.
> 
Fixed.

> > +	tuple_dictionary_unref(dict);
> >  	return lbox_push_tuple_format(L, format);
> >  }
> >  
> 

New patch:

From 0d5bbc6e95394cc772ab05d6af03bd1cee6c6536 Mon Sep 17 00:00:00 2001
From: Mergen Imeev <imeevma@gmail.com>
Date: Wed, 30 Oct 2019 13:39:14 +0300
Subject: [PATCH] netbox: fix memory leak in connect()

This patch fixes memory leak in lbox_tuple_format_new().

Closes #4588

diff --git a/src/box/lua/misc.cc b/src/box/lua/misc.cc
index 7b8b9dc..79b6cfe 100644
--- a/src/box/lua/misc.cc
+++ b/src/box/lua/misc.cc
@@ -231,6 +231,12 @@ lbox_tuple_format_new(struct lua_State *L)
 	struct tuple_format *format =
 		tuple_format_new(&tuple_format_runtime->vtab, NULL, NULL, 0,
 				 NULL, 0, 0, dict, false, false);
+	/*
+	 * Since dictionary reference counter is 1 from the
+	 * beginning and after creation of the tuple_format
+	 * increases by one, we must decrease it once.
+	 */
+	tuple_dictionary_unref(dict);
 	if (format == NULL)
 		return luaT_error(L);
 	return lbox_push_tuple_format(L, format);

  reply	other threads:[~2019-10-31  9:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 10:58 [Tarantool-patches] " imeevma
2019-10-30 22:13 ` Vladislav Shpilevoy
2019-10-31  9:33   ` Mergen Imeev [this message]
2019-10-31 15:23 ` Konstantin Osipov
2019-10-31 16:43   ` Imeev Mergen
2019-11-02 16:26     ` Vladislav Shpilevoy
2019-11-05 10:38 ` [Tarantool-patches] [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191031093326.GA3276@tarantool.org \
    --to=imeevma@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [tarantool-patches] Re: [PATCH v1 1/1] netbox: fix memleak in lbox_tuple_format_new()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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