Skip to contentSkip to conversation

docproc: handle realloc() failure in find_all_symbols()

PATCH New Arjun Sreedharan 1 participant 1 message Feb 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docproc: handle realloc() failure in find_all_symbols()

check realloc rc and avoid potential null dereference and memory leak

---
 scripts/docproc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
scripts/docproc.c +8 -0
index e267e621..438fc91 100644
@@ -396,6 +396,10 @@ static void find_all_symbols(char *filename)
 						   4096)) > 0) {
 					data_len += ret;
 					data = realloc(data, data_len + 4096);
+					if (data == NULL) {
+						perror("realloc");
+						exit(1);
+					}
 				}
 			} while (ret == -EAGAIN);
 			if (ret != 0) {
@@ -420,6 +424,10 @@ static void find_all_symbols(char *filename)
 	start = all_list_len;
 	all_list_len += count;
 	all_list = realloc(all_list, sizeof(char *) * all_list_len);
+	if (all_list == NULL) {
+		perror("realloc");
+		exit(1);
+	}
 	str = data;
 	for (i = 0; i < data_len && start != all_list_len; i++) {
 		if (data[i] == '\0') {
Signature · 1 line
1.8.1.msysgit.1