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] setup_tdb : fix memory leak
Date: Tue, 30 Nov 2021 14:40:38 +0800 [thread overview]
Message-ID: <3a0cbb4e-6ea3-356a-433d-3a7a6466b018@huawei.com> (raw)
In setup_tdb(), need free tdb_dir before return,
otherwise it will cause memory leak.
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
---
e2fsck/dirinfo.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/e2fsck/dirinfo.c b/e2fsck/dirinfo.c
index 49d624c5..a2b36d8e 100644
--- a/e2fsck/dirinfo.c
+++ b/e2fsck/dirinfo.c
@@ -49,7 +49,7 @@ static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
ext2_ino_t threshold;
errcode_t retval;
mode_t save_umask;
- char *tdb_dir, uuid[40];
+ char *tdb_dir = NULL, uuid[40];
int fd, enable;
profile_get_string(ctx->profile, "scratch_files", "directory", 0, 0,
@@ -61,11 +61,11 @@ static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
if (!enable || !tdb_dir || access(tdb_dir, W_OK) ||
(threshold && num_dirs <= threshold))
- return;
+ goto error;
retval = ext2fs_get_mem(strlen(tdb_dir) + 64, &db->tdb_fn);
if (retval)
- return;
+ goto error;
uuid_unparse(ctx->fs->super->s_uuid, uuid);
sprintf(db->tdb_fn, "%s/%s-dirinfo-XXXXXX", tdb_dir, uuid);
@@ -74,7 +74,7 @@ static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
umask(save_umask);
if (fd < 0) {
db->tdb = NULL;
- return;
+ goto error;
}
if (num_dirs < 99991)
@@ -83,6 +83,11 @@ static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
db->tdb = tdb_open(db->tdb_fn, num_dirs, TDB_NOLOCK | TDB_NOSYNC,
O_RDWR | O_CREAT | O_TRUNC, 0600);
close(fd);
+
+error:
+ if(tdb_dir) {
+ free(tdb_dir);
+ }
}
#endif
--
2.23.0
next reply other threads:[~2021-11-30 6:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 6:40 zhanchengbin [this message]
2021-12-10 3:35 ` [PATCH] setup_tdb : fix memory leak zhanchengbin
2021-12-31 1:30 ` Zhiqiang Liu
2022-01-03 12:31 ` riteshh
2022-01-04 2:34 ` zhanchengbin
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=3a0cbb4e-6ea3-356a-433d-3a7a6466b018@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