public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: zhanchengbin <zhanchengbin1@huawei.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: <linux-ext4@vger.kernel.org>, <liuzhiqiang26@huawei.com>,
	<linfeilong@huawei.com>
Subject: [PATCH 6/6] lib/ext2fs: call ext2fs_free_mem() to free &io->name in exception branch
Date: Fri, 3 Dec 2021 14:31:14 +0800	[thread overview]
Message-ID: <7bd86fda-90f1-601f-05b2-b247b5dd6bed@huawei.com> (raw)
In-Reply-To: <37c58382-9714-7e99-6c4d-01b78cfdbd26@huawei.com>

In the exception branch,if we donot call ext2fs_free_mem() to
free &io->name, memory leak will occur.

Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
  lib/ext2fs/test_io.c | 2 ++
  lib/ext2fs/undo_io.c | 2 ++
  2 files changed, 4 insertions(+)

diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c
index 480e68fc..6843edbc 100644
--- a/lib/ext2fs/test_io.c
+++ b/lib/ext2fs/test_io.c
@@ -248,6 +248,8 @@ static errcode_t test_open(const char *name, int 
flags, io_channel *channel)
      return 0;

  cleanup:
+    if (io && io->name)
+        ext2fs_free_mem(&io->name);
      if (io)
          ext2fs_free_mem(&io);
      if (data)
diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c
index eb56f53d..0d4915cb 100644
--- a/lib/ext2fs/undo_io.c
+++ b/lib/ext2fs/undo_io.c
@@ -788,6 +788,8 @@ cleanup:
          free(data->tdb_file);
      if (data && data->real)
          io_channel_close(data->real);
+    if (io && io->name)
+        ext2fs_free_mem(&io->name);
      if (data)
          ext2fs_free_mem(&data);
      if (io)
-- 
2.23.0

      parent reply	other threads:[~2021-12-03  6:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03  6:24 [PATCH 0/6] solve memory leak and check whether NULL pointer zhanchengbin
2021-12-03  6:26 ` [PATCH 1/6] e2fsck: set s->len=0 if malloc() fails in alloc_string() zhanchengbin
2021-12-03  6:31   ` Zhiqiang Liu
2021-12-03  6:27 ` [PATCH 2/6] lib/ss: check whether argp is null before accessing it in ss_execute_command() zhanchengbin
2021-12-03  6:28 ` [PATCH 3/6] lib/support: check whether inump is null before accessing it in quota_set_sb_inum() zhanchengbin
2021-12-03  6:29 ` [PATCH 4/6] e2fsprogs: call ext2fs_badblocks_list_free() to free list in exception branch zhanchengbin
2021-12-03  6:30 ` [PATCH 5/6] e2fsck: check whether ldesc is null before accessing it in end_problem_latch() zhanchengbin
2021-12-03  6:31 ` zhanchengbin [this message]

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=7bd86fda-90f1-601f-05b2-b247b5dd6bed@huawei.com \
    --to=zhanchengbin1@huawei.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=liuzhiqiang26@huawei.com \
    --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