Skip to content

Commit

Permalink
cube/char_samp: Fix some memory leaks
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stweil committed Nov 28, 2016
1 parent 614f44a commit f60ff4d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cube/char_samp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit f60ff4d

Please sign in to comment.