Fix memory leaks

This commit is contained in:
Capacitor Set 2016-11-14 19:01:42 +01:00 committed by jacob1
parent 2d5d9287c6
commit 2d4c195c86
2 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
#include <cassert>
#ifdef WIN #ifdef WIN
#include <shlobj.h> #include <shlobj.h>
#include <shlwapi.h> #include <shlwapi.h>
@ -31,7 +32,9 @@ char *ExecutableName(void)
uint32_t max = 64, res; uint32_t max = 64, res;
if (_NSGetExecutablePath(fn, &max) != 0) if (_NSGetExecutablePath(fn, &max) != 0)
{ {
fn = (char*)realloc(fn, max); char *realloced_fn = (char*)realloc(fn, max);
assert(realloced_fn != NULL);
fn = realloced_fn;
_NSGetExecutablePath(fn, &max); _NSGetExecutablePath(fn, &max);
} }
if (realpath(fn, name) == NULL) if (realpath(fn, name) == NULL)
@ -51,7 +54,9 @@ char *ExecutableName(void)
#endif #endif
#ifndef MACOSX #ifndef MACOSX
max *= 2; max *= 2;
name = (char *)realloc(name, max); char* realloced_name = (char *)realloc(name, max);
assert(realloced_name != NULL);
name = realloced_name;
memset(name, 0, max); memset(name, 0, max);
} }
#endif #endif

View File

@ -1010,8 +1010,10 @@ void Simulation::ApplyDecorationFill(Renderer *ren, int x, int y, int colR, int
return; return;
memset(bitmap, 0, XRES*YRES); memset(bitmap, 0, XRES*YRES);
if (!ColorCompare(ren, x, y, replaceR, replaceG, replaceB)) if (!ColorCompare(ren, x, y, replaceR, replaceG, replaceB)) {
free(bitmap);
return; return;
}
try try
{ {