diff options
author | yexo <yexo@openttd.org> | 2010-02-25 20:06:11 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-02-25 20:06:11 +0000 |
commit | 7ff55502f04f9f75b01879ea04518c14d4706046 (patch) | |
tree | f48f911cf9861a0053bd35b92bf1e0ece0a5bf58 /src/newgrf_config.cpp | |
parent | a9c8dbc0a0e1f1fc4434cf0c83ff658ab8d9e3d9 (diff) | |
download | openttd-7ff55502f04f9f75b01879ea04518c14d4706046.tar.xz |
(svn r19256) -Codechange: use a constructor/destructor for GRFConfig to make sure all members are properly initialized
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r-- | src/newgrf_config.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 31e51d9af..a942279c8 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -20,6 +20,21 @@ #include "fileio_func.h" #include "fios.h" +GRFConfig::GRFConfig(const char *filename) +{ + if (filename != NULL) this->filename = strdup(filename); +} + +GRFConfig::~GRFConfig() +{ + /* GCF_COPY as in NOT strdupped/alloced the filename, name and info */ + if (!HasBit(this->flags, GCF_COPY)) { + free(this->filename); + free(this->name); + free(this->info); + delete this->error; + } +} GRFConfig *_all_grfs; GRFConfig *_grfconfig; @@ -105,27 +120,13 @@ bool FillGRFDetails(GRFConfig *config, bool is_static) } -void ClearGRFConfig(GRFConfig **config) -{ - /* GCF_COPY as in NOT strdupped/alloced the filename, name and info */ - if (!HasBit((*config)->flags, GCF_COPY)) { - free((*config)->filename); - free((*config)->name); - free((*config)->info); - delete (*config)->error; - } - free(*config); - *config = NULL; -} - - /* Clear a GRF Config list */ void ClearGRFConfigList(GRFConfig **config) { GRFConfig *c, *next; for (c = *config; c != NULL; c = next) { next = c->next; - ClearGRFConfig(&c); + delete c; } *config = NULL; } @@ -138,7 +139,7 @@ void ClearGRFConfigList(GRFConfig **config) */ GRFConfig *DuplicateGRFConfig(const GRFConfig *c) { - GRFConfig *config = MallocT<GRFConfig>(1); + GRFConfig *config = new GRFConfig(); *config = *c; if (c->filename != NULL) config->filename = strdup(c->filename); @@ -203,7 +204,7 @@ static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list) if (cur->ident.grfid != list->ident.grfid) continue; prev->next = cur->next; - ClearGRFConfig(&cur); + delete cur; cur = prev; // Just go back one so it continues as normal later on } @@ -320,8 +321,7 @@ public: bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length) { - GRFConfig *c = CallocT<GRFConfig>(1); - c->filename = strdup(filename + basepath_length); + GRFConfig *c = new GRFConfig(filename + basepath_length); bool added = true; if (FillGRFDetails(c, false)) { @@ -355,7 +355,7 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length) if (!added) { /* File couldn't be opened, or is either not a NewGRF or is a * 'system' NewGRF or it's already known, so forget about it. */ - ClearGRFConfig(&c); + delete c; } return added; |