(svn r7518) -Codechange: more NULL pointer resets after free.
authorDarkvater
Wed, 20 Dec 2006 21:17:33 +0000
changeset 5347 18836f961808
parent 5346 0d7cc9cefd2b
child 5348 0f05b1348b5a
(svn r7518) -Codechange: more NULL pointer resets after free.
network_gamelist.c
newgrf_config.c
newgrf_config.h
--- a/network_gamelist.c	Wed Dec 20 20:43:52 2006 +0000
+++ b/network_gamelist.c	Wed Dec 20 21:17:33 2006 +0000
@@ -59,9 +59,10 @@
 			}
 
 			/* Remove GRFConfig information */
-			ClearGRFConfigList(remove->info.grfconfig);
+			ClearGRFConfigList(&remove->info.grfconfig);
+			free(remove);
+			remove = NULL;
 
-			free(remove);
 			DEBUG(net, 4) ("[NET][GameList] Removed server from list");
 			UpdateNetworkGameWindow(false);
 			return;
--- a/newgrf_config.c	Wed Dec 20 20:43:52 2006 +0000
+++ b/newgrf_config.c	Wed Dec 20 21:17:33 2006 +0000
@@ -96,17 +96,21 @@
 
 
 /* Clear a GRF Config list */
-void ClearGRFConfigList(GRFConfig *config)
+void ClearGRFConfigList(GRFConfig **config)
 {
 	GRFConfig *c, *next;
-	for (c = config; c != NULL; c = next) {
+	for (c = *config; c != NULL; c = next) {
 		next = c->next;
 		ClearGRFConfig(&c);
 	}
+	*config = NULL;
 }
 
 
-/* Copy a GRF Config list */
+/** Copy a GRF Config list
+ * @param dst pointer to destination list
+ * @param srt pointer to source list values
+ * @return pointer to the last value added to the destination list */
 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
 {
 	GRFConfig *c;
@@ -131,8 +135,7 @@
 {
 	GRFConfig **c = &_grfconfig;
 
-	ClearGRFConfigList(_grfconfig);
-	_grfconfig = NULL;
+	ClearGRFConfigList(c);
 
 	if (defaults) c = CopyGRFConfigList(c, _grfconfig_newgame);
 	CopyGRFConfigList(c, _grfconfig_static);
@@ -244,8 +247,7 @@
 {
 	uint num;
 
-	ClearGRFConfigList(_all_grfs);
-	_all_grfs = NULL;
+	ClearGRFConfigList(&_all_grfs);
 
 	DEBUG(grf, 1) ("[GRF] Scanning for NewGRFs");
 	num = ScanPath(_paths.data_dir);
@@ -388,7 +390,7 @@
 	/* Append static NewGRF configuration */
 	CopyGRFConfigList(last, _grfconfig_static);
 
-	ClearGRFConfigList(_grfconfig);
+	ClearGRFConfigList(&_grfconfig);
 	_grfconfig = first;
 }
 
--- a/newgrf_config.h	Wed Dec 20 20:43:52 2006 +0000
+++ b/newgrf_config.h	Wed Dec 20 21:17:33 2006 +0000
@@ -45,7 +45,7 @@
 GRFConfig *GetGRFConfig(uint32 grfid);
 GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src);
 void ClearGRFConfig(GRFConfig **config);
-void ClearGRFConfigList(GRFConfig *config);
+void ClearGRFConfigList(GRFConfig **config);
 void ResetGRFConfig(bool defaults);
 bool IsGoodGRFConfigList(void);
 bool FillGRFDetails(GRFConfig *config, bool is_static);