From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 7C3D7445320 for ; Wed, 8 Jul 2020 15:16:37 +0300 (MSK) Received: by mail-lf1-f67.google.com with SMTP id y18so26739310lfh.11 for ; Wed, 08 Jul 2020 05:16:37 -0700 (PDT) Date: Wed, 8 Jul 2020 15:16:34 +0300 From: Cyrill Gorcunov Message-ID: <20200708121634.GC1999@grain> References: <1594210027-332-1-git-send-email-alyapunov@tarantool.org> <1594210027-332-2-git-send-email-alyapunov@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1594210027-332-2-git-send-email-alyapunov@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH] Fix wrong make_scoped_guard usage List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aleksandr Lyapunov Cc: tarantool-patches@dev.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