From b06ce8456a894faa80efd788eee0e2f4597e27fe Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 28 Mar 2012 19:44:33 +0000 Subject: [PATCH] Make g_grpNamePtr memory-clean, extern clearGrpNamePtr(). git-svn-id: https://svn.eduke32.com/eduke32@2563 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 12 +++++------- polymer/eduke32/source/game.h | 2 ++ polymer/eduke32/source/startgtk.game.c | 10 ++++++++-- polymer/eduke32/source/startwin.game.c | 10 ++++++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 0be048f6d..20f3d1111 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -119,8 +119,8 @@ char defsfilename[BMAX_PATH] = "duke3d.def"; static char defaultconfilename[2][BMAX_PATH] = { "EDUKE.CON", "GAME.CON" }; const char *defaultrtsfilename = "DUKE.RTS"; -// g_defNamePtr can ONLY point to one of: defaultduke3dgrp, -// settings[].selectedgrp, malloc'd block (all length BMAX_PATH) +// g_grpNamePtr can ONLY point to one of: defaultduke3dgrp, malloc'd block (all +// length BMAX_PATH) char *g_grpNamePtr = defaultduke3dgrp; // g_defNamePtr can ONLY point to one of: defsfilename, malloc'd block (all // length BMAX_PATH) @@ -134,12 +134,10 @@ const char *g_gameNamePtr = NULL; // g_rtsNamePtr can point to an argv[] element const char *g_rtsNamePtr = NULL; -// FIXME: I am leaking! -// FIXME: make me extern! -static void clearGrpNamePtr(void) +void clearGrpNamePtr(void) { -// if (g_grpNamePtr != defaultduke3dgrp) && not one of settings[].selectedgrp -// Bfree(g_grpNamePtr); + if (g_grpNamePtr != defaultduke3dgrp) + Bfree(g_grpNamePtr); // g_grpNamePtr assumed to be assigned to right after } diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index 414154708..bccbef92b 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -241,7 +241,9 @@ extern int8_t g_noFloorPal[MAXPALOOKUPS]; extern user_defs ud; //extern int32_t g_yax_smoothratio; + void clearDefNamePtr(void); +void clearGrpNamePtr(void); int32_t A_CheckInventorySprite(spritetype *s); int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int32_t s_pn,int32_t s_s,int32_t s_xr,int32_t s_yr,int32_t s_a,int32_t s_ve,int32_t s_zv,int32_t s_ow,int32_t s_ss); diff --git a/polymer/eduke32/source/startgtk.game.c b/polymer/eduke32/source/startgtk.game.c index 992797f45..5f5f00e7b 100644 --- a/polymer/eduke32/source/startgtk.game.c +++ b/polymer/eduke32/source/startgtk.game.c @@ -31,6 +31,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "grpscan.h" #include "build.h" +#include "game.h" +#include "common.h" + #define RDR_POLYMOST 3 // sould be defined elsewhere #define RDR_POLYMER 4 // sould be defined elsewhere @@ -883,7 +886,7 @@ int32_t startwin_run(void) settings.custommoddir = g_modDir; settings.forcesetup = ud.config.ForceSetup; settings.game = g_gameType; - Bstrncpy(settings.selectedgrp, g_grpNamePtr, BMAX_PATH); + Bstrncpyz(settings.selectedgrp, g_grpNamePtr, BMAX_PATH); if (ud.config.NoAutoLoad) settings.autoload = FALSE; else settings.autoload = TRUE; #ifdef POLYMER @@ -909,7 +912,10 @@ int32_t startwin_run(void) ud.config.UseMouse = settings.usemouse; ud.config.UseJoystick = settings.usejoy; ud.config.ForceSetup = settings.forcesetup; - g_grpNamePtr = settings.selectedgrp; + + clearGrpNamePtr(); + g_grpNamePtr = dup_filename(settings.selectedgrp); + g_gameType = settings.game; if (settings.custommoddir != NULL) Bstrcpy(g_modDir, settings.custommoddir); diff --git a/polymer/eduke32/source/startwin.game.c b/polymer/eduke32/source/startwin.game.c index 367425c06..9bbaf96bc 100644 --- a/polymer/eduke32/source/startwin.game.c +++ b/polymer/eduke32/source/startwin.game.c @@ -44,6 +44,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "startwin.game.h" +#include "game.h" +#include "common.h" + #define TAB_CONFIG 0 // #define TAB_GAME 1 #define TAB_MESSAGES 1 @@ -735,7 +738,7 @@ int32_t startwin_run(void) settings.usejoy = ud.config.UseJoystick; settings.game = g_gameType; // settings.crcval = 0; - Bstrncpy(settings.selectedgrp, g_grpNamePtr, BMAX_PATH); + Bstrncpyz(settings.selectedgrp, g_grpNamePtr, BMAX_PATH); settings.gamedir = g_modDir; PopulateForm(-1); @@ -775,7 +778,10 @@ int32_t startwin_run(void) ud.config.ForceSetup = settings.forcesetup; ud.config.UseMouse = settings.usemouse; ud.config.UseJoystick = settings.usejoy; - g_grpNamePtr = settings.selectedgrp; + + clearGrpNamePtr(); + g_grpNamePtr = dup_filename(settings.selectedgrp); + g_gameType = settings.game; if (g_noSetup == 0 && settings.gamedir != NULL)