From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Aleksandr Lyapunov <alyapunov@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] Fix wrong make_scoped_guard usage
Date: Wed, 8 Jul 2020 15:16:34 +0300 [thread overview]
Message-ID: <20200708121634.GC1999@grain> (raw)
In-Reply-To: <1594210027-332-2-git-send-email-alyapunov@tarantool.org>
On Wed, Jul 08, 2020 at 03:07:07PM +0300, Aleksandr Lyapunov wrote:
> The common pitfall of using a lambda is wrong type of capture -
> by value instead of by reference. The simple example is:
> struct sequence_def *new_def = NULL;
> auto def_guard = make_scoped_guard([=] { free(new_def); });
> // initialize new_def
> The problem is that the lambda captures pointer by value, that
> is NULL and will remain NULL in the lambda while new_def is
> successfully initialized in function scope.
>
> The patch fixes the problem above and a couple of similar mistakes.
I think we could use shorter [&] form but this is just
a personal preference. Thank you, good catch!
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
next prev parent reply other threads:[~2020-07-08 12:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 12:07 [Tarantool-patches] [PATCH] Fix " Aleksandr Lyapunov
2020-07-08 12:07 ` [Tarantool-patches] [PATCH] Fix wrong " Aleksandr Lyapunov
2020-07-08 12:15 ` Timur Safin
2020-07-08 12:16 ` Cyrill Gorcunov [this message]
2020-07-09 10:24 ` Nikita Pettik
2020-07-08 12:08 ` [Tarantool-patches] [PATCH] Fix " Aleksandr Lyapunov
2020-07-13 13:40 ` 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=20200708121634.GC1999@grain \
--to=gorcunov@gmail.com \
--cc=alyapunov@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH] Fix wrong make_scoped_guard usage' \
/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