Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp500029pxb; Thu, 25 Feb 2021 07:52:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjwX5H9l5p/XkiPVy/cU3Q6KarFSd8CsMxem8BxPWxGbUe5cWfbjLb68J4Qij1sGZo2oQ0 X-Received: by 2002:a17:906:d18e:: with SMTP id c14mr3135586ejz.62.1614268359615; Thu, 25 Feb 2021 07:52:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614268359; cv=none; d=google.com; s=arc-20160816; b=O+0uCIpxvH16dwjwFiUEqQKuziQ3xOKaOCrlFvyAS3MMeejWIE3YEJQT2jB6sFN8iQ yTPdWZAUEPMzZQLFyJBYUz2cuXqUGHXGmNeiiXj0P8T41zpaXemZNswRrrjOtW+9CKJJ ZlyviKcDoO4dZ6N9IM4KxwwkaBYoJGa+nxt8UO0Ozu71dDxPw5rip00zUxRbhi0P7PYk NdKf04dclBQGYQJqnTdYXOZbF54QRoAu2ta90oi53IyukbcArRjct40BS5CJvMRvN6qx g7QOB/u7JNvPnjq9aSWHJMhn1MM2MrTLqxLRSzJtqsr4onc1B040wjgNXk/xy1/WVFr5 h8tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Fb7gxRr2wVatpvn5aFDNDRiaxp2zR7KmrBYbUmV1cqE=; b=IwMn1umJNQ7wlQ1hJ4XJvDi/ILGFNJPwxkZBh6uUgLzmwQaYcRSQF7eUfQF+AKjbeX 9jZcpTDd6Q9Yi/a/xczELxB2lBnZ+5bWD1+2EQarpLAqbpWoq9nl4xtCK2atgbNVxR6g FbcrkZ1uEcXlxE1CbGnNWQRWYwQPEv3wZhJnl2zv0/Gqsz8KY83BoSX75COxA7YYLfsJ 7ZvzdRlKHprXo9II6PK2wL1G5jD+qJy1vW2OXgs1x7iD0IMx2XouKmqVJ+2r5toAa62W LvEyiSR34Le34rn4me3Ap4rHRhq8nU7zguymif41LCV7yiYunwIKYdYHA0W0sb6O5aPD qgfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jOYCxez3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si3557491edq.397.2021.02.25.07.52.13; Thu, 25 Feb 2021 07:52:39 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jOYCxez3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbhBYPwE (ORCPT + 99 others); Thu, 25 Feb 2021 10:52:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbhBYPwD (ORCPT ); Thu, 25 Feb 2021 10:52:03 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0BC8C06174A for ; Thu, 25 Feb 2021 07:51:21 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id a22so9650554ejv.9 for ; Thu, 25 Feb 2021 07:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Fb7gxRr2wVatpvn5aFDNDRiaxp2zR7KmrBYbUmV1cqE=; b=jOYCxez3lLDcIR0qFmP+dikhSvZg85a38b3WQ3oAO0A/nfRPn17Bed9jUmssxYlb9z l0qwsRg76ZHPoU/xeJmx8JsZa8RSfZsQo7MZN46jma0FTNUfF2y9WcVnIpHqk0JJWkhf 2uWHLp9d57SAOGPjmc95d53UCWIxUkK3hU+R6Ab/zIrFNCLRMkbN8zxFWr85lS46Tokd LSR2EtbOlSVqLOHIEjIHpooq55tOfXSRgKWpC57w9RW8JFnChOIvGFNDlQhEwYfUtND4 tBDjS6xyQT3RdBUt9R3E9dXOJZiSna9hOXcCQVbWMMWBSy1ilaVlROdxbpeBoERFWnKi F/hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Fb7gxRr2wVatpvn5aFDNDRiaxp2zR7KmrBYbUmV1cqE=; b=h2rDaWlOXd+GhegAEhHVFvmL30F1eNHWw+8PgxIrw3tmj3O+trUAJk+CyQ/9DOVdRh RsESHt7lo6hIlntiZXDDUh7Ai4OHnHTQs5Nf8dj3Lzxh95QOiQw1zo4L/AGpYFIDGjpu 8j37elmxgy4YWtCOFH1HeLL7BTMbVJMJSFhL3A+MnYGZSgcv7c57o19Qtpg6VHsPbeNU 1d1j0k1/LUNNr+WM/RlLG7ZXy+U9D3QaCqTVRUhyK3L+YAlwLzqYIDA1qogO5+yze/9J YAy2UUohQrmPLqu+YA3Y2RGAdHi2mm0kbZpE+VEBVIiHgnOtyRXAj2Q1ZZNrn3WhnzAo 36SA== X-Gm-Message-State: AOAM531cSNJwWWPoFSjq3CTUYPwzSEwTovTvsbQFCn56qeMfGpWsp7V9 lGdzRRPh7ERu3zndwXB1E+cj967D8YAxpx9viYKUVR6D30g= X-Received: by 2002:a17:906:a099:: with SMTP id q25mr3177374ejy.549.1614268280408; Thu, 25 Feb 2021 07:51:20 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: harshad shirwadkar Date: Thu, 25 Feb 2021 07:51:09 -0800 Message-ID: Subject: Re: [PATCH] debugfs: fix memory leak problem in read_list() To: Zhiqiang Liu Cc: Ext4 Developers List , "Theodore Y. Ts'o" , linfeilong , lihaotian , "lijinlin (A)" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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. - Harshad > if (*e == '-') { > y = strtoull(e + 1, NULL, 0); > - if (errno) > - return errno; > + if (errno) { > + retval = errno; > + break; > + } > } else if (*e != 0) { > retval = EINVAL; > break; > -- > 2.19.1 > >