fixed some memory allocations to prevent valgrind warnings
authorHolger Schemel <info@artsoft.org>
Wed, 17 Apr 2019 20:02:18 +0000 (22:02 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 17 Apr 2019 20:02:18 +0000 (22:02 +0200)
src/game_sp/Globals.c
src/game_sp/Globals.h
src/game_sp/init.c

index a73a6ffd68f3a1241dd693029cfc9985768afb05..0ca6500049f0c3cb1e07bed3428eea1ddd7a4cd9 100644 (file)
@@ -5,6 +5,9 @@
 #include "Globals.h"
 
 
+static int *PlayField16Mem;
+static byte *PlayField8Mem;
+
 boolean LevelLoaded;
 
 boolean DemoAvailable;
@@ -167,16 +170,22 @@ void InitGlobals(void)
   menBorder = False;
 
   // add preceding playfield buffer (as large as preceding memory area)
-  PlayField16 = checked_calloc((game_sp.preceding_buffer_size +
-                               SP_MAX_PLAYFIELD_SIZE +
-                               SP_HEADER_SIZE) * sizeof(int));
-  PlayField16 = &PlayField16[game_sp.preceding_buffer_size];
+  PlayField16Mem = checked_calloc((game_sp.preceding_buffer_size +
+                                  SP_MAX_PLAYFIELD_SIZE +
+                                  SP_HEADER_SIZE) * sizeof(int));
+  PlayField16 = &PlayField16Mem[game_sp.preceding_buffer_size];
 
   // add preceding playfield buffer (as large as one playfield row)
-  PlayField8 = checked_calloc((SP_MAX_PLAYFIELD_WIDTH +
-                              SP_MAX_PLAYFIELD_SIZE +
-                              SP_HEADER_SIZE) * sizeof(byte));
-  PlayField8 = &PlayField8[SP_MAX_PLAYFIELD_WIDTH];
+  PlayField8Mem = checked_calloc((SP_MAX_PLAYFIELD_WIDTH +
+                                 SP_MAX_PLAYFIELD_SIZE +
+                                 SP_HEADER_SIZE) * sizeof(byte));
+  PlayField8 = &PlayField8Mem[SP_MAX_PLAYFIELD_WIDTH];
+}
+
+void FreeGlobals(void)
+{
+  checked_free(PlayField16Mem);
+  checked_free(PlayField8Mem);
 }
 
 int GetSI(int X, int Y)
index a202d07df139482eee5939941267d2202b7a99d4..bcb8dad3da471be2662543bc8f8923821a9a2599 100644 (file)
@@ -271,6 +271,7 @@ int GetStretchY(int si);
 int GetX(int si);
 int GetY(int si);
 void InitGlobals(void);
+void FreeGlobals(void);
 
 void PrepareLevel(void);
 
index 040c18f9be7a117857685ae613824c381893805f..4b001ae44c777fc17f978caf1f5ff7e103b52895 100644 (file)
@@ -64,6 +64,7 @@ void sp_open_all(void)
 
 void sp_close_all(void)
 {
+  FreeGlobals();
 }
 
 void InitPrecedingPlayfieldMemory(void)