From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752640AbbB1UHz (ORCPT ); Sat, 28 Feb 2015 15:07:55 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:39080 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751660AbbB1UHy (ORCPT ); Sat, 28 Feb 2015 15:07:54 -0500 From: Arjun Sreedharan To: Masahiro Yamada Cc: Michal Marek , lkml Subject: [PATCH] docproc: handle realloc() failure in find_all_symbols() Date: Sun, 1 Mar 2015 01:37:22 +0530 Message-Id: <1425154042-3474-1-git-send-email-arjun024@gmail.com> X-Mailer: git-send-email 1.7.11.7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org check realloc rc and avoid potential null dereference and memory leak Signed-off-by: Arjun Sreedharan --- scripts/docproc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/docproc.c b/scripts/docproc.c index e267e621..438fc91 100644 --- a/scripts/docproc.c +++ b/scripts/docproc.c @@ -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') { -- 1.8.1.msysgit.1