diff options
author | yexo <yexo@openttd.org> | 2010-02-25 15:54:40 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-02-25 15:54:40 +0000 |
commit | 2c1b7410f3e7f2a50ea3bd8defd687b010a9a910 (patch) | |
tree | 17bc474919d3c4e76be2fe5fad31cfafb92a779f /src/newgrf_config.cpp | |
parent | 14d28c5e699b8b8e82526e28e16e1d80cd0e7a28 (diff) | |
download | openttd-2c1b7410f3e7f2a50ea3bd8defd687b010a9a910.tar.xz |
(svn r19251) -Codechange: add a contructor to GRFError and use it to allocating errors more uniform.
-Fix: some grf error messages didn't free the previous error messages, creating a memory leak
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r-- | src/newgrf_config.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index c996c3f04..28e67e7f5 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -26,6 +26,17 @@ GRFConfig *_grfconfig; GRFConfig *_grfconfig_newgame; GRFConfig *_grfconfig_static; +GRFError::GRFError(StringID severity, StringID message) : + message(message), + severity(severity) +{ +} + +GRFError::~GRFError() +{ + free(this->custom_message); + free(this->data); + } /** * Update the palettes of the graphics from the config file. @@ -101,12 +112,7 @@ void ClearGRFConfig(GRFConfig **config) free((*config)->filename); free((*config)->name); free((*config)->info); - - if ((*config)->error != NULL) { - free((*config)->error->custom_message); - free((*config)->error->data); - free((*config)->error); - } + delete (*config)->error; } free(*config); *config = NULL; @@ -139,8 +145,9 @@ GRFConfig *DuplicateGRFConfig(const GRFConfig *c) if (c->name != NULL) config->name = strdup(c->name); if (c->info != NULL) config->info = strdup(c->info); if (c->error != NULL) { - config->error = MallocT<GRFError>(1); - memcpy(config->error, c->error, sizeof(GRFError)); + config->error = new GRFError(c->error->severity, c->error->message); + config->error->num_params = c->error->num_params; + memcpy(config->error->param_value, c->error->param_value, sizeof(config->error->param_value)); if (c->error->data != NULL) config->error->data = strdup(c->error->data); if (c->error->custom_message != NULL) config->error->custom_message = strdup(c->error->custom_message); } |