Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp847383pxb; Thu, 25 Feb 2021 17:22:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbY/DTeV8sAcsFWeOfCHfexv2nAmhE8LZIs5AAhFjbkOiw5HiB21Tqmq8NPzmDRpvBJuEW X-Received: by 2002:aa7:d58e:: with SMTP id r14mr713112edq.332.1614302573666; Thu, 25 Feb 2021 17:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614302573; cv=none; d=google.com; s=arc-20160816; b=Ft/oOGjza+Hnp9oIV/S7oVayOwKumVx0C/q0En0p6iQjdqqCqLyBlWXHhl2U/q5LQd dXJ8spBYPn9ZM/UKtuTfrjorC+g93yfgNf+m1rxfJfLUoBVz8w5jZzQ65TCBpv3B8USD JHD+BS+kqXPgiN/UvgegN9D+Vn20q05hC8E2GrGu7m2Ts9RCJkZjjf0ki/HJ64tZFF9R /UwJHLddn2ZwvafqB27s5hFXATKi79gRGxBx0XyFuV5T9P+tCZ2Oo0wRjU+MV2lm/AIz FakcEvutiHcN9vsM4B7wCeUM/0oQo2BjvOH6dVm9Sor4J6moNwvXmjATAdyncN7y+30q GAoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=aJGwEflYOSY56GqaiplCXwpvDnK2GuNMwh2adb5urXE=; b=cdZnOBmBf3w5Rj/D5XmgwMY2zNaLFc9QW6+WgNjGet66TonnzFH9VlqHy8YaYh2WOy mLAb/5dtJWvXZvPZwwPLUJ86iUsdJTlpFddREES3MRCphS5CKXTO9dvKAJo2rYk80KbK JXamYZb+m4BcqUaEBbvM7HteMYJdQ9qVz1b78BpYL3+4SSYYlQuERuvdnlThBGKjRPLA zbEgN64BmPjx1GrmPQaX5rFpxhnJn+EuWvKxoTRS/sRdJ01Jm6xkh5P9YIvbDe0gXzCk wumTQtJPvWnpxyjvLQbVhtfCL/QP1vcVhx8aIJcMNhgb3qi8TuyhjuxtMRhxpIRBKIHU GuZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du11si5143198ejc.473.2021.02.25.17.22.24; Thu, 25 Feb 2021 17:22:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229571AbhBZBTu (ORCPT + 99 others); Thu, 25 Feb 2021 20:19:50 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:12208 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbhBZBTs (ORCPT ); Thu, 25 Feb 2021 20:19:48 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DmsFR5r6LzlPM1; Fri, 26 Feb 2021 09:16:59 +0800 (CST) Received: from [127.0.0.1] (10.174.176.117) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Feb 2021 09:18:54 +0800 Subject: Re: [PATCH] debugfs: fix memory leak problem in read_list() To: Theodore Ts'o , harshad shirwadkar CC: Ext4 Developers List , linfeilong , lihaotian , "lijinlin (A)" References: From: Zhiqiang Liu Message-ID: <7a877f93-2500-b2f4-cf8e-971503ba54c6@huawei.com> Date: Fri, 26 Feb 2021 09:18:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.117] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Thank you and harshad shirwadkar. On 2021/2/26 1:02, Theodore Ts'o wrote: > On Thu, Feb 25, 2021 at 07:51:09AM -0800, harshad shirwadkar wrote: >> On Sat, Feb 20, 2021 at 12:41 AM Zhiqiang Liu wrote: >>> >>> >>> In read_list func, if strtoull() fails in while loop, >>> we will return the error code directly. Then, memory of >>> variable lst will be leaked without setting to *list. >>> >>> Signed-off-by: Zhiqiang Liu >>> Signed-off-by: linfeilong >>> --- >>> debugfs/util.c | 12 ++++++++---- >>> 1 file changed, 8 insertions(+), 4 deletions(-) >>> >>> diff --git a/debugfs/util.c b/debugfs/util.c >>> index be6b550e..9e880548 100644 >>> --- a/debugfs/util.c >>> +++ b/debugfs/util.c >>> @@ -530,12 +530,16 @@ errcode_t read_list(char *str, blk64_t **list, size_t *len) >>> >>> errno = 0; >>> y = x = strtoull(tok, &e, 0); >>> - if (errno) >>> - return errno; >>> + if (errno) { >>> + retval = errno; >>> + break; >>> + } >> Shouldn't we have `goto err;` here instead of break? strtoull failure >> here indicates that no valid value was found, so instead of returning >> the allocated memory, we should just free the memory and return error. > > As of commit 462c424500a5 ("debugfs: fix memory allocation failures > when parsing journal_write arguments") there is no longer the err: > goto target. The goal is to move to a model where the caller is > exclusively responsible for freeing any allocated memory, since if > realloc() has gotten into the act, the memory pointed to in *list > would have been freed by realloc(). The fix is to make sure *list is > updated before we return. This also allows the caller to have access > to the list of numbers parsed before we ran into an error. > > So the Zhiqiang's patch is correc, and I will apply it. > > - Ted > > . >