From 64f1b6b89549947a88711ba4f988c9c67c6807b6 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Tue, 18 Jan 2011 00:36:49 +0100 Subject: [PATCH] Fix memory leaks reported by cppcheck --- lib/gamelib/anim.cpp | 1 + lib/script/event.cpp | 1 + lib/sequence/sequence.cpp | 5 ++--- src/main.cpp | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/gamelib/anim.cpp b/lib/gamelib/anim.cpp index d8e5ae29a..d3b0c0b6a 100644 --- a/lib/gamelib/anim.cpp +++ b/lib/gamelib/anim.cpp @@ -172,6 +172,7 @@ BOOL anim_Create3D(char szPieFileName[], UWORD uwStates, UWORD uwFrameRate, UWOR if ( ubType == ANIM_3D_TRANS && uwObj != uwFrames ) { ASSERT(false, "Frames in pie %s != script objects %i", szPieFileName, uwObj); + free(psAnim3D); return false; } diff --git a/lib/script/event.cpp b/lib/script/event.cpp index 3c29547c8..68d0d2a4a 100644 --- a/lib/script/event.cpp +++ b/lib/script/event.cpp @@ -415,6 +415,7 @@ BOOL eventNewContext(SCRIPT_CODE *psCode, CONTEXT_RELEASE release, if (!asCreateFuncs[type](&(psCode->ppsLocalVarVal[i][j]) )) { debug(LOG_ERROR,"eventNewContext: asCreateFuncs failed for local var"); + free(psContext); return false; } } diff --git a/lib/sequence/sequence.cpp b/lib/sequence/sequence.cpp index 1c0b44218..b3825f58c 100644 --- a/lib/sequence/sequence.cpp +++ b/lib/sequence/sequence.cpp @@ -671,9 +671,7 @@ bool seq_Play(const char* filename) /* open video */ if (theora_p) { - char *blackframe = (char *)calloc(1, texture_width * texture_height * 4); - if (videodata.ti.frame_width > texture_width || - videodata.ti.frame_height > texture_height) + if (videodata.ti.frame_width > texture_width || videodata.ti.frame_height > texture_height) { debug(LOG_ERROR, "Video size too large, must be below %dx%d!", texture_width, texture_height); @@ -684,6 +682,7 @@ bool seq_Play(const char* filename) debug(LOG_ERROR, "Video not in YUV420 format!"); return false; } + char *blackframe = (char *)calloc(1, texture_width * texture_height * 4); Allocate_videoFrame(); glGenTextures(1, &video_texture); diff --git a/src/main.cpp b/src/main.cpp index 0d95c55a4..50b7f36de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -270,14 +270,13 @@ void clearOverrideMods(void) void addLoadedMod(const char * modname) { - char * mod = strdup(modname); - int i, modlen; if (num_loaded_mods >= MAX_MODS) { // mod list full return; } - modlen = strlen(mod); + char *mod = strdup(modname); + int modlen = strlen(mod); if (modlen >= 3 && strcmp(&mod[modlen-3], ".wz")==0) { // remove ".wz" from end @@ -305,7 +304,8 @@ void addLoadedMod(const char * modname) // Yes, this is an online insertion sort. // I swear, for the numbers of mods this is going to be dealing with // (i.e. 0 to 2), it really is faster than, say, Quicksort. - for (i=0; i0; i++) {} + int i; + for (i = 0; i < num_loaded_mods && strcmp(loaded_mods[i], mod) > 0; i++) {} if (i < num_loaded_mods) { if (strcmp(loaded_mods[i], mod) == 0)