From: trix@redhat.com
To: dhowells@redhat.com, jlayton@kernel.org
Cc: linux-kernel@vger.kernel.org, Tom Rix <trix@redhat.com>
Subject: [PATCH] vfs: samples: fix memory leak
Date: Sun, 9 Aug 2020 10:06:36 -0700 [thread overview]
Message-ID: <20200809170636.22133-1-trix@redhat.com> (raw)
From: Tom Rix <trix@redhat.com>
clang static analysis reports this represenative problem
test-fsinfo.c:615:3: warning: Potential leak of memory pointed to by 'r'
memset(r, 0xbd, buf_size);
^~~~~~
r dynamically allocated in a loop an increasing size.
for (;;) {
r = malloc(buf_size);
...
buf_size = (ret + 4096 - 1) & ~(4096 - 1);
}
The problem is that r is never freed at the bottom of the loop.
So free r.
Signed-off-by: Tom Rix <trix@redhat.com>
---
samples/vfs/test-fsinfo.c | 1 +
samples/vfs/test-mntinfo.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/samples/vfs/test-fsinfo.c b/samples/vfs/test-fsinfo.c
index aa122fb555b6..d669201d03ac 100644
--- a/samples/vfs/test-fsinfo.c
+++ b/samples/vfs/test-fsinfo.c
@@ -622,6 +622,7 @@ static ssize_t get_fsinfo(const char *file, const char *name,
if (ret <= buf_size - 1)
break;
buf_size = (ret + 4096 - 1) & ~(4096 - 1);
+ free(r);
}
if (debug)
diff --git a/samples/vfs/test-mntinfo.c b/samples/vfs/test-mntinfo.c
index 40125ad81f17..54a6abf4a8b0 100644
--- a/samples/vfs/test-mntinfo.c
+++ b/samples/vfs/test-mntinfo.c
@@ -105,6 +105,7 @@ static void *get_attr_alloc(unsigned int mnt_id, unsigned int attr,
break;
}
buf_size = (ret + 4096 - 1) & ~(4096 - 1);
+ free(r);
}
return r;
--
2.18.1
reply other threads:[~2020-08-09 17:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200809170636.22133-1-trix@redhat.com \
--to=trix@redhat.com \
--cc=dhowells@redhat.com \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).