Author: cazfi
Date: Sat Feb  6 08:35:58 2016
New Revision: 31787

URL: http://svn.gna.org/viewcvs/freeciv?rev=31787&view=rev
Log:
Fixed removal of the event_cache entries not to happen inside iteration through 
their own
list.

See bug #24283

Modified:
    branches/S2_5/server/notify.c

Modified: branches/S2_5/server/notify.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/notify.c?rev=31787&r1=31786&r2=31787&view=diff
==============================================================================
--- branches/S2_5/server/notify.c       (original)
+++ branches/S2_5/server/notify.c       Sat Feb  6 08:35:58 2016
@@ -426,15 +426,11 @@
 static bool event_cache_status = FALSE;
 
 /**************************************************************************
-  Destroy an event_cache_data.  Removes it from the cache.
-**************************************************************************/
-static void event_cache_data_destroy(struct event_cache_data *pdata)
-{
-  fc_assert_ret(NULL != event_cache);
-  fc_assert_ret(NULL != pdata);
-
-  event_cache_data_list_remove(event_cache, pdata);
-  free(pdata);
+  Callback for freeing event cache data
+**************************************************************************/
+static void event_cache_data_free(struct event_cache_data *data)
+{
+  free(data);
 }
 
 /**************************************************************************
@@ -489,7 +485,7 @@
                ? game.server.event_cache.max_size
                : GAME_MAX_EVENT_CACHE_MAX_SIZE;
   while (event_cache_data_list_size(event_cache) > max_events) {
-    event_cache_data_destroy(event_cache_data_list_get(event_cache, 0));
+    event_cache_data_list_pop_front(event_cache);
   }
 
   return pdata;
@@ -503,7 +499,7 @@
   if (event_cache != NULL) {
     event_cache_free();
   }
-  event_cache = event_cache_data_list_new();
+  event_cache = event_cache_data_list_new_full(event_cache_data_free);
   event_cache_status = TRUE;
 }
 
@@ -513,9 +509,6 @@
 void event_cache_free(void)
 {
   if (event_cache != NULL) {
-    event_cache_iterate(pdata) {
-      event_cache_data_destroy(pdata);
-    } event_cache_iterate_end;
     event_cache_data_list_destroy(event_cache);
     event_cache = NULL;
   }
@@ -527,9 +520,7 @@
 **************************************************************************/
 void event_cache_clear(void)
 {
-  event_cache_iterate(pdata) {
-    event_cache_data_destroy(pdata);
-  } event_cache_iterate_end;
+  event_cache_data_list_clear(event_cache);
 }
 
 /**************************************************************************
@@ -537,11 +528,16 @@
 **************************************************************************/
 void event_cache_remove_old(void)
 {
-  event_cache_iterate(pdata) {
-    if (pdata->turn + game.server.event_cache.turns <= game.info.turn) {
-      event_cache_data_destroy(pdata);
-    }
-  } event_cache_iterate_end;
+  struct event_cache_data *current;
+
+  /* This assumes that entries are in order, the ones to be removed first. */
+  current = event_cache_data_list_get(event_cache, 0);
+
+  while (current != NULL
+         && current->turn + game.server.event_cache.turns <= game.info.turn) {
+    event_cache_data_list_pop_front(event_cache);
+    current = event_cache_data_list_get(event_cache, 0);
+  }
 }
 
 /**************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to