From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bu7U3-0005GP-Si for qemu-devel@nongnu.org; Tue, 11 Oct 2016 20:33:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bu7U1-0007Ry-SV for qemu-devel@nongnu.org; Tue, 11 Oct 2016 20:33:22 -0400 Message-ID: <57FD8686.9030802@cn.fujitsu.com> Date: Wed, 12 Oct 2016 08:40:38 +0800 From: Changlong Xie MIME-Version: 1.0 References: <1476182772-11693-1-git-send-email-xiecl.fnst@cn.fujitsu.com> <1476182772-11693-2-git-send-email-xiecl.fnst@cn.fujitsu.com> <5074b60f-3c8e-07e5-a17a-e16a54313979@redhat.com> In-Reply-To: <5074b60f-3c8e-07e5-a17a-e16a54313979@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/2] block/replication: prefect the logic to acquire 'top_id' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake , qemu devel , qemu block , Stefan Hajnoczi , Fam Zheng , Max Reitz , Kevin Wolf , Wen Congyang On 10/11/2016 10:52 PM, Eric Blake wrote: > On 10/11/2016 05:46 AM, Changlong Xie wrote: >> Only g_strdup(top_id) if 'top_id' is not NULL, although there >> is no memory leak here >> >> Signed-off-by: Changlong Xie >> --- >> block/replication.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/block/replication.c b/block/replication.c >> index 3bd1cf1..5b432d9 100644 >> --- a/block/replication.c >> +++ b/block/replication.c >> @@ -104,11 +104,11 @@ static int replication_open(BlockDriverState *bs, QDict *options, >> } else if (!strcmp(mode, "secondary")) { >> s->mode = REPLICATION_MODE_SECONDARY; >> top_id = qemu_opt_get(opts, REPLICATION_TOP_ID); >> - s->top_id = g_strdup(top_id); > > g_strdup(NULL) is safe; it returns NULL in that case. Yes, that's why i said 'there is no memory leak here' in the commit message. > >> - if (!s->top_id) { >> + if (!top_id) { >> error_setg(&local_err, "Missing the option top-id"); >> goto fail; >> } >> + s->top_id = g_strdup(top_id); > > I see no point to this patch, rather than churn. It just reduce on execution path. Maybe i'm too academic :) Will remove it in the next series. Thanks -Xie >