From 21392fa9b1498f874aa688545b9e501a84c04812 Mon Sep 17 00:00:00 2001 From: Murai Takashi Date: Fri, 1 Feb 2019 20:29:58 +0900 Subject: [PATCH] mail: Fix PVS 965 Fix memory leak when realloc() fails. Change-Id: I8f7fb3ce7f43de03f76e8f0ee14277d79a55ee63 Reviewed-on: https://review.haiku-os.org/c/1005 Reviewed-by: Adrien Destugues --- src/apps/mail/WIndex.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/apps/mail/WIndex.cpp b/src/apps/mail/WIndex.cpp index 9a39c52c16..76b38da4ba 100644 --- a/src/apps/mail/WIndex.cpp +++ b/src/apps/mail/WIndex.cpp @@ -268,9 +268,14 @@ WIndex::_BlockCheck(void) if (fEntries < fMaxEntries) return B_OK; fBlocks = fEntries / fEntriesPerBlock + 1; - fEntryList = (uint8 *)realloc(fEntryList, fBlockSize * fBlocks); - if (!fEntryList) + uint8* tmpEntryList = (uint8 *)realloc(fEntryList, fBlockSize * fBlocks); + if (!tmpEntryList) { + free(fEntryList); + fEntryList = NULL; return B_ERROR; + } else { + fEntryList = tmpEntryList; + } return B_OK; }