- The game is now free of leaks up to the point just after the wads are loaded.

- Fixed: Although TypeInfos are now deleted at exit, their FlatPointers or ActorInfo
  data was not freed. I chose not to use a destructor to handle this, because then it
  would no longer be a POD type that can be statically initialized.
- Fixed: Aliases were not deleted at exit.
- Fixed: FWadCollection did not free its hash tables, lump info, full names, or the
  list of open files when destroyed.


SVN r85 (trunk)
This commit is contained in:
Randy Heit 2006-05-09 00:02:37 +00:00
parent d4160f7211
commit 748d7bf4b1
9 changed files with 151 additions and 50 deletions

View file

@ -10,6 +10,13 @@ May 7, 2006 (Changes by Graf Zahl)
a label, in addition to goto. a label, in addition to goto.
May 6, 2006 May 6, 2006
- The game is now free of leaks up to the point just after the wads are loaded.
- Fixed: Although TypeInfos are now deleted at exit, their FlatPointers or ActorInfo
data was not freed. I chose not to use a destructor to handle this, because then it
would no longer be a POD type that can be statically initialized.
- Fixed: Aliases were not deleted at exit.
- Fixed: FWadCollection did not free its hash tables, lump info, full names, or the
list of open files when destroyed.
- Updated Italian strings that someone kindly e-mailed to me. - Updated Italian strings that someone kindly e-mailed to me.
- The CRT no longer detects any memory leaks when I run to the IWAD picker and quit. - The CRT no longer detects any memory leaks when I run to the IWAD picker and quit.
- Fixed: The memory used to hold the path to zdoom.wad/.pk3 was not freed if - Fixed: The memory used to hold the path to zdoom.wad/.pk3 was not freed if

View file

@ -64,8 +64,6 @@ static const char *KeyConfCommands[] =
"setslot" "setslot"
}; };
static long ParseCommandLine (const char *args, int *argc, char **argv); static long ParseCommandLine (const char *args, int *argc, char **argv);
CVAR (Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered? CVAR (Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered?
@ -149,7 +147,32 @@ FActionMap ActionMaps[] =
{ 0xf01cb105, &Button_LookUp, "lookup" }, { 0xf01cb105, &Button_LookUp, "lookup" },
}; };
#define NUM_ACTIONS (sizeof(ActionMaps)/sizeof(FActionMap)) #define NUM_ACTIONS countof(ActionMaps)
static struct AliasKiller
{
~AliasKiller()
{
// Scan the hash table for all aliases and delete them.
// Regular commands will be destroyed automatically.
for (size_t i = 0; i < countof(Commands); ++i)
{
FConsoleCommand *cmd = Commands[i];
while (cmd != NULL)
{
FConsoleCommand *next = cmd->m_Next;
if (cmd->IsAlias())
{
delete cmd;
}
cmd = next;
}
}
}
} KillTheAliases;
IMPLEMENT_CLASS (DWaitingCommand) IMPLEMENT_CLASS (DWaitingCommand)

View file

@ -47,9 +47,9 @@
#include "r_state.h" #include "r_state.h"
#include "stats.h" #include "stats.h"
TypeInfo::DeletingArray TypeInfo::m_RuntimeActors; TArray<TypeInfo *> TypeInfo::m_RuntimeActors;
TArray<TypeInfo *> TypeInfo::m_Types (256); TArray<TypeInfo *> TypeInfo::m_Types (256);
unsigned int TypeInfo::TypeHash[256]; // Why can't I use TypeInfo::HASH_SIZE? unsigned int TypeInfo::TypeHash[TypeInfo::HASH_SIZE]; // Why can't I use TypeInfo::HASH_SIZE?
#if defined(_MSC_VER) || defined(__GNUC__) #if defined(_MSC_VER) || defined(__GNUC__)
#include "autosegs.h" #include "autosegs.h"
@ -77,15 +77,60 @@ TypeInfo DObject::_StaticType(NULL, "DObject", NULL, sizeof(DObject));
static cycle_t StaleCycles; static cycle_t StaleCycles;
static int StaleCount; static int StaleCount;
TypeInfo::DeletingArray::~DeletingArray() // A harmless non_NULL FlatPointer for classes without pointers.
static const size_t TheEnd = ~0;
static struct TypeInfoDataFreeer
{ {
for (unsigned int i = 0; i < Size(); ++i) ~TypeInfoDataFreeer()
{ {
if ((*this)[i] != NULL) TArray<size_t *> uniqueFPs(64);
unsigned int i, j;
for (i = 0; i < TypeInfo::m_Types.Size(); ++i)
{ {
delete (*this)[i]; TypeInfo *type = TypeInfo::m_Types[i];
(*this)[i] = NULL; if (type->FlatPointers != &TheEnd && type->FlatPointers != type->Pointers)
{
// FlatPointers are shared by many classes, so we must check for
// duplicates and only delete those that are unique.
for (j = 0; j < uniqueFPs.Size(); ++j)
{
if (type->FlatPointers == uniqueFPs[j])
{
break;
}
}
if (j == uniqueFPs.Size())
{
uniqueFPs.Push(const_cast<size_t *>(type->FlatPointers));
}
}
// For runtime classes, this call will also delete the TypeInfo.
TypeInfo::StaticFreeData (type);
} }
for (i = 0; i < uniqueFPs.Size(); ++i)
{
delete[] uniqueFPs[i];
}
}
} FreeTypeInfoData;
void TypeInfo::StaticFreeData (TypeInfo *type)
{
if (type->ActorInfo != NULL)
{
delete type->ActorInfo;
type->ActorInfo = NULL;
}
if (type->bRuntimeClass)
{
if (type->Name != NULL)
{
delete[] type->Name;
}
type->Name = NULL;
delete type;
} }
} }
@ -199,6 +244,7 @@ TypeInfo *TypeInfo::CreateDerivedClass (char *name, unsigned int size)
type->RegisterType(); type->RegisterType();
type->Meta = Meta; type->Meta = Meta;
type->FlatPointers = NULL; type->FlatPointers = NULL;
type->bRuntimeClass = true;
// If this class has an actor info, then any classes derived from it // If this class has an actor info, then any classes derived from it
// also need an actor info. // also need an actor info.
@ -233,8 +279,6 @@ TypeInfo *TypeInfo::CreateDerivedClass (char *name, unsigned int size)
// to the same array as the super class's. // to the same array as the super class's.
void TypeInfo::BuildFlatPointers () void TypeInfo::BuildFlatPointers ()
{ {
static const size_t TheEnd = ~0;
if (FlatPointers != NULL) if (FlatPointers != NULL)
{ // Already built: Do nothing. { // Already built: Do nothing.
return; return;

View file

@ -133,6 +133,7 @@ private:
struct TypeInfo struct TypeInfo
{ {
static void StaticInit (); static void StaticInit ();
static void StaticFreeData (TypeInfo *type);
const char *Name; const char *Name;
TypeInfo *ParentType; TypeInfo *ParentType;
@ -142,6 +143,7 @@ struct TypeInfo
FActorInfo *ActorInfo; FActorInfo *ActorInfo;
unsigned int HashNext; unsigned int HashNext;
unsigned short TypeIndex; unsigned short TypeIndex;
bool bRuntimeClass; // class was defined at run-time, not compile-time
FMetaTable Meta; FMetaTable Meta;
const size_t *FlatPointers; // object pointers defined by this class and all its superclasses; not initialized by default const size_t *FlatPointers; // object pointers defined by this class and all its superclasses; not initialized by default
@ -169,16 +171,8 @@ struct TypeInfo
static const TypeInfo *FindType (const char *name); static const TypeInfo *FindType (const char *name);
static const TypeInfo *IFindType (const char *name); static const TypeInfo *IFindType (const char *name);
// The DeletingArray deletes all the TypeInfos it points to
// when it gets destroyed.
class DeletingArray : public TArray<TypeInfo *>
{
public:
~DeletingArray();
};
static TArray<TypeInfo *> m_Types; static TArray<TypeInfo *> m_Types;
static DeletingArray m_RuntimeActors; static TArray<TypeInfo *> m_RuntimeActors;
enum { HASH_SIZE = 256 }; enum { HASH_SIZE = 256 };
static unsigned int TypeHash[HASH_SIZE]; static unsigned int TypeHash[HASH_SIZE];

View file

@ -166,6 +166,47 @@ FWadCollection::FWadCollection ()
FWadCollection::~FWadCollection () FWadCollection::~FWadCollection ()
{ {
if (FirstLumpIndex != NULL)
{
delete[] FirstLumpIndex;
FirstLumpIndex = NULL;
}
if (NextLumpIndex != NULL)
{
delete[] NextLumpIndex;
NextLumpIndex = NULL;
}
if (FirstLumpIndex_FullName != NULL)
{
delete[] FirstLumpIndex_FullName;
FirstLumpIndex_FullName = NULL;
}
if (NextLumpIndex_FullName != NULL)
{
delete[] NextLumpIndex_FullName;
NextLumpIndex_FullName = NULL;
}
if (LumpInfo != NULL)
{
for (DWORD i = 0; i < NumLumps; ++i)
{
if (LumpInfo[i].fullname != NULL)
{
delete[] LumpInfo[i].fullname;
}
}
delete[] LumpInfo;
LumpInfo = NULL;
}
if (Wads != NULL)
{
for (DWORD i = 0; i < NumWads; ++i)
{
delete Wads[i];
}
delete[] Wads;
Wads = NULL;
}
} }
//========================================================================== //==========================================================================

View file

@ -1262,9 +1262,9 @@ int max;
void ErrorMsg(const char *filename, int lineno, const char *format, ...){ void ErrorMsg(const char *filename, int lineno, const char *format, ...){
char errmsg[ERRMSGSIZE]; char errmsg[ERRMSGSIZE];
char prefix[PREFIXLIMIT+10]; char prefix[PREFIXLIMIT+10];
int errmsgsize; size_t errmsgsize;
int prefixsize; size_t prefixsize;
int availablewidth; size_t availablewidth;
va_list ap; va_list ap;
int end, restart, base; int end, restart, base;
@ -1494,7 +1494,7 @@ char **argv;
/* /*
** Return a pointer to the next structure in the linked list. ** Return a pointer to the next structure in the linked list.
*/ */
#define NEXT(A) (*(char**)(((unsigned long)A)+offset)) #define NEXT(A) (*(char**)(((size_t)A)+offset))
/* /*
** Inputs: ** Inputs:
@ -1568,11 +1568,11 @@ char *list;
char **next; char **next;
int (*cmp)(); int (*cmp)();
{ {
unsigned long offset; size_t offset;
char *ep; char *ep;
char *set[LISTSIZE]; char *set[LISTSIZE];
int i; int i;
offset = (unsigned long)next - (unsigned long)list; offset = (size_t)next - (size_t)list;
for(i=0; i<LISTSIZE; i++) set[i] = 0; for(i=0; i<LISTSIZE; i++) set[i] = 0;
while( list ){ while( list ){
ep = list; ep = list;
@ -1604,7 +1604,8 @@ int n;
int k; int k;
FILE *err; FILE *err;
{ {
int spcnt, i; size_t spcnt;
int i;
spcnt = 0; spcnt = 0;
if( argv[0] ) fprintf(err,"%s",argv[0]); if( argv[0] ) fprintf(err,"%s",argv[0]);
spcnt = strlen(argv[0]) + 1; spcnt = strlen(argv[0]) + 1;
@ -1722,7 +1723,7 @@ FILE *err;
if( *end ){ if( *end ){
if( err ){ if( err ){
fprintf(err,"%sillegal character in floating-point argument.\n",emsg); fprintf(err,"%sillegal character in floating-point argument.\n",emsg);
errline(i,((unsigned long)end)-(unsigned long)argv[i],err); errline(i,((size_t)end)-(size_t)argv[i],err);
} }
errcnt++; errcnt++;
} }
@ -1733,7 +1734,7 @@ FILE *err;
if( *end ){ if( *end ){
if( err ){ if( err ){
fprintf(err,"%sillegal character in integer argument.\n",emsg); fprintf(err,"%sillegal character in integer argument.\n",emsg);
errline(i,((unsigned long)end)-(unsigned long)argv[i],err); errline(i,((size_t)end)-(size_t)argv[i],err);
} }
errcnt++; errcnt++;
} }
@ -1828,7 +1829,7 @@ int n;
void OptPrint(){ void OptPrint(){
int i; int i;
int max, len; size_t max, len;
max = 0; max = 0;
for(i=0; op[i].label; i++){ for(i=0; op[i].label; i++){
len = strlen(op[i].label) + 1; len = strlen(op[i].label) + 1;
@ -2304,7 +2305,7 @@ to follow the previous rule.");
** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and ** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and
** comments them out. Text in between is also commented out as appropriate. ** comments them out. Text in between is also commented out as appropriate.
*/ */
static int preprocess_input(char *z){ static void preprocess_input(char *z){
int i, j, k, n; int i, j, k, n;
int exclude = 0; int exclude = 0;
int start = 1; int start = 1;
@ -2624,7 +2625,7 @@ struct lemon *lemp;
maxlen = 10; maxlen = 10;
for(i=0; i<lemp->nsymbol; i++){ for(i=0; i<lemp->nsymbol; i++){
sp = lemp->symbols[i]; sp = lemp->symbols[i];
len = strlen(sp->name); len = (int)strlen(sp->name);
if( len>maxlen ) maxlen = len; if( len>maxlen ) maxlen = len;
} }
ncolumns = 76/(maxlen+5); ncolumns = 76/(maxlen+5);
@ -3037,8 +3038,8 @@ struct lemon *lemp;
*/ */
PRIVATE char *append_str(char *zText, int n, int p1, int p2){ PRIVATE char *append_str(char *zText, int n, int p1, int p2){
static char *z = 0; static char *z = 0;
static int alloced = 0; static size_t alloced = 0;
static int used = 0; static size_t used = 0;
int c; int c;
char zInt[40]; char zInt[40];
@ -3051,7 +3052,7 @@ PRIVATE char *append_str(char *zText, int n, int p1, int p2){
used += n; used += n;
assert( used>=0 ); assert( used>=0 );
} }
n = strlen(zText); n = (int)strlen(zText);
} }
if( n+sizeof(zInt)*2+used >= alloced ){ if( n+sizeof(zInt)*2+used >= alloced ){
alloced = n + sizeof(zInt)*2 + used + 200; alloced = n + sizeof(zInt)*2 + used + 200;
@ -3207,13 +3208,13 @@ int mhflag; /* True if generating makeheaders output */
for(i=0; i<arraysize; i++) types[i] = 0; for(i=0; i<arraysize; i++) types[i] = 0;
maxdtlength = 0; maxdtlength = 0;
if( lemp->vartype ){ if( lemp->vartype ){
maxdtlength = strlen(lemp->vartype); maxdtlength = (int)strlen(lemp->vartype);
} }
for(i=0; i<lemp->nsymbol; i++){ for(i=0; i<lemp->nsymbol; i++){
int len; int len;
struct symbol *sp = lemp->symbols[i]; struct symbol *sp = lemp->symbols[i];
if( sp->datatype==0 ) continue; if( sp->datatype==0 ) continue;
len = strlen(sp->datatype); len = (int)strlen(sp->datatype);
if( len>maxdtlength ) maxdtlength = len; if( len>maxdtlength ) maxdtlength = len;
} }
stddt = (char*)malloc( maxdtlength*2 + 1 ); stddt = (char*)malloc( maxdtlength*2 + 1 );
@ -3410,7 +3411,7 @@ int mhflag; /* Output in makeheaders format if true */
name = lemp->name ? lemp->name : "Parse"; name = lemp->name ? lemp->name : "Parse";
if( lemp->arg && lemp->arg[0] ){ if( lemp->arg && lemp->arg[0] ){
int i; int i;
i = strlen(lemp->arg); i = (int)strlen(lemp->arg);
while( i>=1 && isspace(lemp->arg[i-1]) ) i--; while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--; while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++; fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++;

View file

@ -27,7 +27,7 @@ void showIns(std::ostream &o, const Ins &i, const Ins &base){
case CHAR: { case CHAR: {
o << "match "; o << "match ";
for(const Ins *j = &(&i)[1]; j < (Ins*) i.i.link; ++j) for(const Ins *j = &(&i)[1]; j < (Ins*) i.i.link; ++j)
prtCh(o, j->c.value); prtCh(o, (const uchar)j->c.value);
break; break;
} case GOTO: } case GOTO:
o << "goto " << ((Ins*) i.i.link - &base); o << "goto " << ((Ins*) i.i.link - &base);

View file

@ -127,7 +127,7 @@ DFA::DFA(Ins *ins, uint ni, uint lb, uint ub, Char *rep)
if(i->i.tag == CHAR){ if(i->i.tag == CHAR){
for(Ins *j = i + 1; j < (Ins*) i->i.link; ++j){ for(Ins *j = i + 1; j < (Ins*) i->i.link; ++j){
if(!(j->c.link = goTo[j->c.value - lb].to)) if(!(j->c.link = goTo[j->c.value - lb].to))
goTo[nGoTos++].ch = j->c.value; goTo[nGoTos++].ch = (Char)j->c.value;
goTo[j->c.value - lb].to = j; goTo[j->c.value - lb].to = j;
} }
} else if(i->i.tag == TERM){ } else if(i->i.tag == TERM){

View file

@ -3994,9 +3994,6 @@
<File <File
RelativePath=".\src\g_strife\a_alienspectres.cpp"> RelativePath=".\src\g_strife\a_alienspectres.cpp">
</File> </File>
<File
RelativePath=".\src\g_strife\a_beggars.cpp">
</File>
<File <File
RelativePath=".\src\g_strife\a_coin.cpp"> RelativePath=".\src\g_strife\a_coin.cpp">
</File> </File>
@ -4015,15 +4012,9 @@
<File <File
RelativePath=".\src\g_strife\a_macil.cpp"> RelativePath=".\src\g_strife\a_macil.cpp">
</File> </File>
<File
RelativePath=".\src\g_strife\a_merchants.cpp">
</File>
<File <File
RelativePath=".\src\g_strife\a_oracle.cpp"> RelativePath=".\src\g_strife\a_oracle.cpp">
</File> </File>
<File
RelativePath=".\src\g_strife\a_peasant.cpp">
</File>
<File <File
RelativePath=".\src\g_strife\a_programmer.cpp"> RelativePath=".\src\g_strife\a_programmer.cpp">
</File> </File>