From 2f200ac49322ff8ccd13c5e8b7a22abbf6ff2610 Mon Sep 17 00:00:00 2001 From: Julien Date: Sat, 4 Jun 2011 03:43:16 +0800 Subject: ANALYSIS: Fix potential memory leak when using realloc When reallocation is unsuccessful, the passed buffer is not freed. In this case, assigning the result (NULL) will result in a leak of the original memory buffer. See http://msdn.microsoft.com/en-us/library/kkedhy7c.aspx --- audio/decoders/voc.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'audio/decoders/voc.cpp') diff --git a/audio/decoders/voc.cpp b/audio/decoders/voc.cpp index 74ea4440a1..be53f945ac 100644 --- a/audio/decoders/voc.cpp +++ b/audio/decoders/voc.cpp @@ -118,7 +118,11 @@ static byte *loadVOCFromStream(Common::ReadStream &stream, int &size, int &rate, debug(9, "VOC Data Block: %d, %d, %d", rate, packing, len); if (packing == 0) { if (size) { - ret_sound = (byte *)realloc(ret_sound, size + len); + byte *tmp = (byte *)realloc(ret_sound, size + len); + if (!tmp) + error("Cannot reallocate memory for VOC Data Block"); + + ret_sound = tmp; } else { ret_sound = (byte *)malloc(len); } -- cgit v1.2.3