From f60ff4d57560b2daf03951015dd188446ce50024 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 28 Nov 2016 15:09:06 +0100 Subject: [PATCH] cube/char_samp: Fix some memory leaks Coverity report: CID 1164722 (#9 of 9): Resource leak (RESOURCE_LEAK) 20. leaked_storage: Variable label32 going out of scope leaks the storage it points to. Signed-off-by: Stefan Weil --- cube/char_samp.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cube/char_samp.cpp b/cube/char_samp.cpp index c3493fa13c..4c4059d6bc 100644 --- a/cube/char_samp.cpp +++ b/cube/char_samp.cpp @@ -112,6 +112,7 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) { // read label if (fp->Read(label32, val32 * sizeof(*label32)) != (val32 * sizeof(*label32))) { + delete [] label32; return NULL; } // null terminate @@ -121,33 +122,42 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) { } // read coordinates if (fp->Read(&page, sizeof(page)) != sizeof(page)) { + delete [] label32; return NULL; } if (fp->Read(&left, sizeof(left)) != sizeof(left)) { + delete [] label32; return NULL; } if (fp->Read(&top, sizeof(top)) != sizeof(top)) { + delete [] label32; return NULL; } if (fp->Read(&first_char, sizeof(first_char)) != sizeof(first_char)) { + delete [] label32; return NULL; } if (fp->Read(&last_char, sizeof(last_char)) != sizeof(last_char)) { + delete [] label32; return NULL; } if (fp->Read(&norm_top, sizeof(norm_top)) != sizeof(norm_top)) { + delete [] label32; return NULL; } if (fp->Read(&norm_bottom, sizeof(norm_bottom)) != sizeof(norm_bottom)) { + delete [] label32; return NULL; } if (fp->Read(&norm_aspect_ratio, sizeof(norm_aspect_ratio)) != sizeof(norm_aspect_ratio)) { + delete [] label32; return NULL; } // create the object CharSamp *char_samp = new CharSamp(); if (char_samp == NULL) { + delete [] label32; return NULL; } // init @@ -163,6 +173,7 @@ CharSamp *CharSamp::FromCharDumpFile(CachedFile *fp) { // load the Bmp8 part if (char_samp->LoadFromCharDumpFile(fp) == false) { delete char_samp; + delete [] label32; return NULL; } return char_samp;