Author: cazfi Date: Sat Feb 6 08:35:38 2016 New Revision: 31785 URL: http://svn.gna.org/viewcvs/freeciv?rev=31785&view=rev Log: Fixed removal of the event_cache entries not to happen inside iteration through their own list.
See bug #24283 Modified: trunk/server/notify.c Modified: trunk/server/notify.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/notify.c?rev=31785&r1=31784&r2=31785&view=diff ============================================================================== --- trunk/server/notify.c (original) +++ trunk/server/notify.c Sat Feb 6 08:35:38 2016 @@ -471,15 +471,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); } /************************************************************************** @@ -533,7 +529,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; @@ -547,7 +543,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; } @@ -557,9 +553,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; } @@ -571,9 +564,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); } /************************************************************************** @@ -581,11 +572,16 @@ **************************************************************************/ void event_cache_remove_old(void) { - event_cache_iterate(pdata) { - if (pdata->packet.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->packet.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