(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning

values to it. This cuts down on memleaks which could exist when the function was
 not used carefully.
This commit is contained in:
Darkvater
2006-12-21 10:09:43 +00:00
parent 85cd063a9d
commit 5cd081b6cd

View File

@@ -115,6 +115,8 @@ GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
{ {
GRFConfig *c; GRFConfig *c;
/* Clear destination as it will be overwritten */
ClearGRFConfigList(dst);
for (; src != NULL; src = src->next) { for (; src != NULL; src = src->next) {
c = calloc(1, sizeof(*c)); c = calloc(1, sizeof(*c));
*c = *src; *c = *src;
@@ -135,8 +137,6 @@ void ResetGRFConfig(bool defaults)
{ {
GRFConfig **c = &_grfconfig; GRFConfig **c = &_grfconfig;
ClearGRFConfigList(c);
if (defaults) c = CopyGRFConfigList(c, _grfconfig_newgame); if (defaults) c = CopyGRFConfigList(c, _grfconfig_newgame);
CopyGRFConfigList(c, _grfconfig_static); CopyGRFConfigList(c, _grfconfig_static);
} }