From: Arjun Sreedharan <arjun024@gmail.com>
To: Michal Marek <mmarek@suse.cz>
Cc: linux-kernel@vger.kernel.org,
Masahiro Yamada <yamada.m@jp.panasonic.com>
Subject: [PATCH] docproc: fix potential memory leak in find_all_symbols()
Date: Thu, 11 Dec 2014 19:21:37 +0530 [thread overview]
Message-ID: <1418305897-1879-1-git-send-email-arjun024@gmail.com> (raw)
in case realloc() fails, @data is overwritten by NULL losing
reference to the memory. This is avoided by @data_old
Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
---
scripts/docproc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/scripts/docproc.c b/scripts/docproc.c
index e267e621..e230c0b 100644
--- a/scripts/docproc.c
+++ b/scripts/docproc.c
@@ -359,7 +359,8 @@ static void find_all_symbols(char *filename)
int ret, i, count, start;
char real_filename[PATH_MAX + 1];
int pipefd[2];
- char *data, *str;
+ char *data, *data_old;
+ char *str;
size_t data_len = 0;
vec[0] = KERNELDOC;
@@ -395,7 +396,13 @@ static void find_all_symbols(char *filename)
data + data_len,
4096)) > 0) {
data_len += ret;
+ data_old = data;
data = realloc(data, data_len + 4096);
+ if (!data) {
+ free(data_old);
+ fprintf(stderr, "Out of memory.\n");
+ exit(1);
+ }
}
} while (ret == -EAGAIN);
if (ret != 0) {
--
1.7.11.7
reply other threads:[~2014-12-11 13:51 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=1418305897-1879-1-git-send-email-arjun024@gmail.com \
--to=arjun024@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.cz \
--cc=yamada.m@jp.panasonic.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.