public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>,
	"Theodore Y. Ts'o" <tytso@mit.edu>
Cc: harshad shirwadkar <harshadshirwadkar@gmail.com>,
	linfeilong <linfeilong@huawei.com>,
	lihaotian <lihaotian9@huawei.com>, <liuzhiqiang26@huawei.com>,
	"lijinlin (A)" <lijinlin3@huawei.com>
Subject: [PATCH] debugfs: fix memory leak problem in read_list()
Date: Sat, 20 Feb 2021 16:41:29 +0800	[thread overview]
Message-ID: <c6fb0951-a472-dbb4-1970-fe9cece5d182@huawei.com> (raw)


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 <liuzhiqiang26@huawei.com>
Signed-off-by: linfeilong <linfeilong@huawei.com>
---
 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;
+		}
 		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



             reply	other threads:[~2021-02-20  8:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-20  8:41 Zhiqiang Liu [this message]
2021-02-25  1:39 ` [PATCH] debugfs: fix memory leak problem in read_list() Zhiqiang Liu
2021-02-25 15:51 ` harshad shirwadkar
2021-02-25 17:02   ` Theodore Ts'o
2021-02-25 17:13     ` harshad shirwadkar
2021-02-26  1:18     ` Zhiqiang Liu

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=c6fb0951-a472-dbb4-1970-fe9cece5d182@huawei.com \
    --to=liuzhiqiang26@huawei.com \
    --cc=harshadshirwadkar@gmail.com \
    --cc=lihaotian9@huawei.com \
    --cc=lijinlin3@huawei.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox