[PATCH] docproc: fix potential memory leak in find_all_symbols()

From: Arjun Sreedharan
Date: Thu Dec 11 2014 - 08:51:52 EST


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@xxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/