From 5859aa719449b2c73ae227777bbad117531667bc Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 11 Jun 2006 01:06:19 +0000 Subject: [PATCH] - Fixed: Information added with addkeysection and addmenukey was never freed. - Fixed: A classic decorate FakeInventory's PickupText was never freed. - Fixed: Colored lights were never freed. - Fixed: When a dehacked patch was applied, the dehacked StateMap was never freed. - Removed termdone checks around atterm(S_ClearSoundData) and atterm(S_Shutdown) because atterm() already checks for duplicates. - Fixed: S_ClearSoundData() should unload all sounds before it clears S_sfx. - Fixed: AltSoundRenderer::LoadSound() didn't check if the sound had already been loaded and lost the old sound data if it had been. - Fixed: FinishDehPatch() needlessly duplicated the new DehackedPickup's name. - Fixed: PatchStrings() allocated a private string and never freed it. SVN r183 (trunk) --- docs/rh-log.txt | 14 +++++++++++ src/c_cmds.cpp | 1 + src/d_dehacked.cpp | 55 +++++++++++++++++++----------------------- src/decorations.cpp | 8 +++--- src/m_options.cpp | 25 +++++++++++++++++++ src/s_advsound.cpp | 14 ++++++----- src/s_sound.cpp | 7 +----- src/sound/altsound.cpp | 7 +++++- src/v_palette.cpp | 19 ++++++++++++++- 9 files changed, 102 insertions(+), 48 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 764ede19d..e409bc6be 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,17 @@ +June 10, 2006 +- Fixed: Information added with addkeysection and addmenukey was never freed. +- Fixed: A classic decorate FakeInventory's PickupText was never freed. +- Fixed: Colored lights were never freed. +- Fixed: When a dehacked patch was applied, the dehacked StateMap was never + freed. +- Removed termdone checks around atterm(S_ClearSoundData) and + atterm(S_Shutdown) because atterm() already checks for duplicates. +- Fixed: S_ClearSoundData() should unload all sounds before it clears S_sfx. +- Fixed: AltSoundRenderer::LoadSound() didn't check if the sound had already + been loaded and lost the old sound data if it had been. +- Fixed: FinishDehPatch() needlessly duplicated the new DehackedPickup's name. +- Fixed: PatchStrings() allocated a private string and never freed it. + June 8, 2006 (Changes by Graf Zahl) - Changed music name handling in MAPINFO so that music can be specified by full path of a file in a Zip. diff --git a/src/c_cmds.cpp b/src/c_cmds.cpp index 697bf4f69..db77990b5 100644 --- a/src/c_cmds.cpp +++ b/src/c_cmds.cpp @@ -692,6 +692,7 @@ CCMD (wdir) if (wadnum < 0) { Printf ("%s must be loaded to view its directory.\n", argv[1]); + return; } for (int i = 0; i < Wads.GetNumLumps(); ++i) { diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 3ef40ec0d..290a92435 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1935,42 +1935,32 @@ donewithtext: static int PatchStrings (int dummy) { - static size_t maxstrlen = 128; - static char *holdstring; int result; DPrintf ("[Strings]\n"); - if (!holdstring) - holdstring = (char *)M_Malloc (maxstrlen); - while ((result = GetLine()) == 1) { - *holdstring = '\0'; + FString holdstring; do { - while (maxstrlen < strlen (holdstring) + strlen (Line2) + 8) + holdstring += skipwhite (Line2); + holdstring.StripRight(); + if (holdstring.Len() > 0 && holdstring[holdstring.Len()-1] == '\\') { - maxstrlen += 128; - holdstring = (char *)M_Realloc (holdstring, maxstrlen); - } - strcat (holdstring, skipwhite (Line2)); - stripwhite (holdstring); - if (holdstring[strlen(holdstring)-1] == '\\') - { - holdstring[strlen(holdstring)-1] = '\0'; + holdstring.Truncate((long)holdstring.Len()-1); Line2 = igets (); - } else + } + else + { Line2 = NULL; + } } while (Line2 && *Line2); - ReplaceSpecialChars (holdstring); - // [RH] There used to be some code here to add % specifiers to - // obituaries that lacked them for compatibility with old ZDoom - // versions. This code was removed when the string table was - // switched to something completely dynamic. + ReplaceSpecialChars (holdstring.LockBuffer()); + holdstring.UnlockBuffer(); GStrings.SetString (Line1, holdstring); - DPrintf ("%s set to:\n%s\n", Line1, holdstring); + DPrintf ("%s set to:\n%s\n", Line1, holdstring.GetChars()); } return result; @@ -2274,6 +2264,11 @@ static void UnloadDehSupp () { if (--DehUseCount <= 0) { + // StateMap is not freed here, because if you load a second + // dehacked patch through some means other than including it + // in the first patch, it won't see the state information + // that was altered by the first. So we need to keep the + // StateMap around until all patches have been applied. DehUseCount = 0; delete[] DehSuppLump; DehSuppLump = NULL; @@ -2283,13 +2278,6 @@ static void UnloadDehSupp () delete[] OrgSprNames; OrgSprNames = NULL; } - /* No! Not if we want to load multiple independant patches! - if (StateMap != NULL) - { - delete[] StateMap; - StateMap = NULL; - } - */ if (BitNames != NULL) { delete[] BitNames; @@ -2531,7 +2519,7 @@ void FinishDehPatch () char typeNameBuilder[32]; sprintf (typeNameBuilder, "DehackedPickup%d", touchedIndex); PClass *subclass = RUNTIME_CLASS(ADehackedPickup)->CreateDerivedClass - (copystring(typeNameBuilder), sizeof(ADehackedPickup)); + (typeNameBuilder, sizeof(ADehackedPickup)); AActor *defaults2 = GetDefaultByType (subclass); memcpy (defaults2, defaults1, sizeof(AActor)); subclass->ActorInfo->GameFilter = type->ActorInfo->GameFilter; @@ -2554,6 +2542,13 @@ void FinishDehPatch () // Since deh.MaxHealth was used incorrectly this can only be set // after finishing with the DEH stuff. if (deh.MaxHealth == -1) deh.MaxHealth = 100; + + // Now that all Dehacked patches have been processed, it's okay to free StateMap. + if (StateMap != NULL) + { + delete[] StateMap; + StateMap = NULL; + } } void HandleNoSector() diff --git a/src/decorations.cpp b/src/decorations.cpp index ff57b2d74..5bc5abc90 100644 --- a/src/decorations.cpp +++ b/src/decorations.cpp @@ -103,16 +103,16 @@ class AFakeInventory : public AInventory { DECLARE_STATELESS_ACTOR (AFakeInventory, AInventory); public: - char *PickupText; bool Respawnable; const char *PickupMessage () { - if (PickupText == 0) + const char *text = GetClass()->Meta.GetMetaString (AIMETA_PickupMessage); + if (text == 0) { return Super::PickupMessage(); } - return PickupText; + return text; } bool ShouldRespawn () @@ -860,7 +860,7 @@ static void ParseInsideDecoration (FActorInfo *info, AActor *defaults, else if (def == DEF_Pickup && SC_Compare ("PickupMessage")) { SC_MustGetString (); - inv->PickupText = copystring (sc_String); + info->Class->Meta.SetMetaString(AIMETA_PickupMessage, sc_String); } else if (def == DEF_Pickup && SC_Compare ("Respawns")) { diff --git a/src/m_options.cpp b/src/m_options.cpp index 2573e3b90..dc27e17ae 100644 --- a/src/m_options.cpp +++ b/src/m_options.cpp @@ -2941,6 +2941,30 @@ void M_SaveCustomKeys (FConfigFile *config, char *section, char *subsection) static int AddKeySpot; +static void FreeKeySections() +{ + const unsigned int numStdControls = countof(ControlsItems); + unsigned int i; + + for (i = numStdControls; i < CustomControlsItems.Size(); ++i) + { + menuitem_t *item = &CustomControlsItems[i]; + if (item->type == whitetext || item->type == control) + { + if (item->label != NULL) + { + delete[] item->label; + item->label = NULL; + } + if (item->e.command != NULL) + { + delete[] item->e.command; + item->e.command = NULL; + } + } + } +} + CCMD (addkeysection) { if (argv.argc() != 3) @@ -2973,6 +2997,7 @@ CCMD (addkeysection) } } + atterm (FreeKeySections); if (i == last) { // Add the new section // Limit the ini name to 32 chars diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index 4ebed76ab..460f68ad0 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -547,6 +547,13 @@ static void S_ClearSoundData() { unsigned int i; + if (GSnd != NULL) + { + for (i = 0; i < S_sfx.Size(); ++i) + { + GSnd->UnloadSound (&S_sfx[i]); + } + } S_sfx.Clear(); for(i = 0; i < countof(Ambients); i++) @@ -584,14 +591,9 @@ static void S_ClearSoundData() void S_ParseSndInfo () { - static bool termdone=false; int lump; - if (!termdone) - { - termdone=true; - atterm (S_ClearSoundData); - } + atterm (S_ClearSoundData); S_ClearSoundData(); // remove old sound data first! CurrentPitchMask = 0; diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 1d58c1774..7a1f8d0ff 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -280,16 +280,11 @@ void S_AddLocalSndInfo(int lump); void S_Init () { - static bool termdone=false; int i; int curvelump; Printf ("S_Init\n"); - if (!termdone) - { - termdone=true; - atterm (S_Shutdown); - } + atterm (S_Shutdown); // remove old data (S_Init can be called multiple times!) LastLocalSndInfo = LastLocalSndSeq = ""; diff --git a/src/sound/altsound.cpp b/src/sound/altsound.cpp index 1f9b75a86..a80fcf996 100644 --- a/src/sound/altsound.cpp +++ b/src/sound/altsound.cpp @@ -632,7 +632,12 @@ void AltSoundRenderer::LoadSound (sfxinfo_t *sfx) SDWORD len; BYTE *sfxdata, *sfxstart; SDWORD size; - + + if (sfx->data != NULL) + { + return; + } + size = sfx->lumpnum >= 0 ? Wads.LumpLength (sfx->lumpnum) : 0; if (size == 0) { diff --git a/src/v_palette.cpp b/src/v_palette.cpp index a925ef9ea..93ce7f2f8 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -63,6 +63,8 @@ BYTE InverseColormap[NUMCOLORMAPS*256]; BYTE GoldColormap[NUMCOLORMAPS*256]; int Near255; +static void FreeSpecialLights();; + FColorMatcher ColorMatcher; /* Current color blending values */ @@ -337,6 +339,8 @@ void InitPalette () bool usingBuild = false; int lump; + atterm (FreeSpecialLights); + if ((lump = Wads.CheckNumForFullName ("palette.dat")) >= 0 && Wads.LumpLength (lump) >= 768) { usingBuild = FixBuildPalette (pal, lump, false); @@ -625,7 +629,7 @@ FDynamicColormap *GetSpecialLights (PalEntry color, PalEntry fade, int desaturat } // Not found. Create it. - colormap = new FDynamicColormap;; + colormap = new FDynamicColormap; colormap->Maps = new BYTE[NUMCOLORMAPS*256]; colormap->Next = NormalLight.Next; colormap->Color = color; @@ -638,6 +642,19 @@ FDynamicColormap *GetSpecialLights (PalEntry color, PalEntry fade, int desaturat return colormap; } +// Free all lights created with GetSpecialLights +static void FreeSpecialLights() +{ + FDynamicColormap *colormap, *next; + + for (colormap = NormalLight.Next; colormap != NULL; colormap = next) + { + next = colormap->Next; + delete[] colormap->Maps; + delete colormap; + } +} + // Builds NUMCOLORMAPS colormaps lit with the specified color void FDynamicColormap::BuildLights () {