Index: client/attribute.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/attribute.c,v retrieving revision 1.13 diff -u -r1.13 attribute.c --- client/attribute.c 2002/06/23 12:35:45 1.13 +++ client/attribute.c 2002/08/20 14:48:00 @@ -60,6 +60,7 @@ const void *pkey = hash_key_by_number(attribute_hash, 0); void *pvalue = hash_delete_entry(attribute_hash, pkey); + free((void *) pkey); free(pvalue); } Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.143 diff -u -r1.143 civclient.c --- client/civclient.c 2002/08/19 23:05:27 1.143 +++ client/civclient.c 2002/08/20 14:48:01 @@ -52,6 +52,7 @@ #include "dialogs_g.h" #include "diplodlg_g.h" #include "gui_main_g.h" +#include "goto.h" #include "helpdata.h" /* boot_help_texts() */ #include "mapctrl_g.h" #include "mapview_g.h" @@ -184,15 +185,7 @@ ui_init(); my_init_network(); init_messages_where(); - init_our_capability(); - game_init(); - - conn_list_init(&game.all_connections); - conn_list_init(&game.est_connections); - conn_list_init(&game.game_connections); - attribute_init(); - agents_init(); load_general_options(); if (tile_set_name[0] == '\0') @@ -228,6 +221,8 @@ attribute_flush(); my_shutdown_network(); + client_game_free(); + exit(EXIT_SUCCESS); } @@ -561,10 +556,34 @@ /************************************************************************** ... **************************************************************************/ +void client_game_init() +{ + game_init(); + attribute_init(); + agents_init(); +} + +/************************************************************************** +... +**************************************************************************/ +void client_game_free() +{ + client_remove_all_cli_conn(); + free_client_goto(); + free_help_texts(); + attribute_free(); + agents_free(); + game_free(); +} + +/************************************************************************** +... +**************************************************************************/ void set_client_state(enum client_states newstate) { bool connect_error = (client_state == CLIENT_PRE_GAME_STATE) && (newstate == CLIENT_PRE_GAME_STATE); + enum client_states oldstate = client_state; if(client_state!=newstate) { @@ -594,13 +613,12 @@ else if(client_state==CLIENT_PRE_GAME_STATE) { popdown_all_city_dialogs(); close_all_diplomacy_dialogs(); - client_remove_all_cli_conn(); set_unit_focus_no_center(NULL); clear_notify_window(); - attribute_free(); - attribute_init(); - game_free(); - game_init(); + if (oldstate != CLIENT_BOOT_STATE) { + client_game_free(); + } + client_game_init(); } update_menus(); } Index: client/civclient.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.h,v retrieving revision 1.20 diff -u -r1.20 civclient.h --- client/civclient.h 2002/07/23 02:48:45 1.20 +++ client/civclient.h 2002/08/20 14:48:01 @@ -56,4 +56,7 @@ bool client_is_observer(void); void real_timer_callback(void); +void client_game_init(void); +void client_game_free(void); + #endif /* FC__CIVCLIENT_H */ Index: client/goto.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v retrieving revision 1.38 diff -u -r1.38 goto.c --- client/goto.c 2002/02/26 19:57:08 1.38 +++ client/goto.c 2002/08/20 14:48:02 @@ -57,6 +57,8 @@ static bool is_active = FALSE; +static bool is_init = FALSE; +static int old_xsize; struct client_goto_map goto_map; /* These are used for all GOTO's */ @@ -206,8 +208,6 @@ void init_client_goto(void) { int x_itr; - static bool is_init = FALSE; - static int old_xsize; if (!goto_array) { goto_array = fc_malloc(INITIAL_ARRAY_LENGTH @@ -216,14 +216,7 @@ } if (is_init) { - for (x_itr = 0; x_itr < old_xsize; x_itr++) { - free(goto_map.move_cost[x_itr]); - free(goto_map.vector[x_itr]); - free(goto_map.drawn[x_itr]); - } - free(goto_map.move_cost); - free(goto_map.vector); - free(goto_map.drawn); + free_client_goto(); } goto_map.move_cost = fc_malloc(map.xsize * sizeof(short *)); @@ -246,6 +239,32 @@ is_init = TRUE; old_xsize = map.xsize; +} + +void free_client_goto() +{ + if (is_init) { + int x_itr; + for (x_itr = 0; x_itr < old_xsize; x_itr++) { + free(goto_map.move_cost[x_itr]); + free(goto_map.vector[x_itr]); + free(goto_map.drawn[x_itr]); + } + free(goto_map.move_cost); + free(goto_map.vector); + free(goto_map.drawn); + + memset(&goto_map,0,sizeof(goto_map)); + + is_init = FALSE; + } + + if (goto_array) { + free(goto_array); + free(waypoint_list); + goto_array = NULL; + waypoint_list = NULL; + } } /********************************************************************** Index: client/goto.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v retrieving revision 1.5 diff -u -r1.5 goto.h --- client/goto.h 2002/02/19 16:41:17 1.5 +++ client/goto.h 2002/08/20 14:48:02 @@ -26,6 +26,7 @@ extern struct client_goto_map goto_map; void init_client_goto(void); +void free_client_goto(void); void enter_goto_state(struct unit *punit); void exit_goto_state(void); bool goto_is_active(void); Index: client/helpdata.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v retrieving revision 1.54 diff -u -r1.54 helpdata.c --- client/helpdata.c 2002/08/07 11:21:39 1.54 +++ client/helpdata.c 2002/08/20 14:48:02 @@ -84,7 +84,7 @@ /**************************************************************** Free all allocations associated with help_nodes. *****************************************************************/ -static void free_help_nodes(void) +void free_help_texts(void) { check_help_nodes_init(); help_list_iterate(help_nodes, ptmp) { @@ -197,7 +197,7 @@ freelog(LOG_VERBOSE, "Booting help texts"); } else { /* free memory allocated last time booted */ - free_help_nodes(); + free_help_texts(); freelog(LOG_VERBOSE, "Rebooting help texts"); } Index: client/helpdata.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/helpdata.h,v retrieving revision 1.6 diff -u -r1.6 helpdata.h --- client/helpdata.h 2002/02/11 10:37:41 1.6 +++ client/helpdata.h 2002/08/20 14:48:02 @@ -21,6 +21,7 @@ }; void boot_help_texts(void); +void free_help_texts(void); int num_help_items(void); const struct help_item *get_help_item(int pos); Index: client/tilespec.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v retrieving revision 1.82 diff -u -r1.82 tilespec.c --- client/tilespec.c 2002/08/15 20:24:09 1.82 +++ client/tilespec.c 2002/08/20 14:48:03 @@ -38,7 +38,6 @@ #include "nation.h" #include "player.h" #include "registry.h" -#include "sbuffer.h" #include "shared.h" #include "support.h" #include "unit.h" @@ -86,9 +85,6 @@ information (including on reconnections etc). */ -static struct sbuffer *sprite_key_sb; -/* used to allocate keys for sprite_hash */ - #define TILESPEC_CAPSTR "+tilespec2 duplicates_ok" /* Tilespec capabilities acceptable to this program: @@ -408,8 +404,7 @@ for(k=0; k0); sprite_hash = hash_new(hash_fval_string, hash_fcmp_string); - sprite_key_sb = sbuf_new(); for(i=0; ilevel > 0); - - memcpy(&priv_agent->agent, agent, sizeof(struct agent)); - - priv_agent->first_outstanding_request_id = 0; - priv_agent->last_outstanding_request_id = 0; - - priv_agent->stats.network_wall_timer = new_timer(TIMER_USER, TIMER_ACTIVE); - priv_agent->stats.wait_at_network = 0; - priv_agent->stats.wait_at_network_requests = 0; - - agents.entries_used++; -} - -/*********************************************************************** If the call described by the given arguments isn't contained in agents.calls list add the call to this list. ***********************************************************************/ @@ -322,6 +287,67 @@ read_timer_seconds(agent->stats.network_wall_timer), agent->stats.wait_at_network_requests, agent->stats.wait_at_network); +} + +/*********************************************************************** + Called once per client startup. +***********************************************************************/ +void agents_init(void) +{ + agents.entries_used = 0; + call_list_init(&agents.calls); + + /* Add init calls of agents here */ + cma_init(); + cmafec_init(); +} + +/*********************************************************************** + ... +***********************************************************************/ +void agents_free(void) +{ + int i; + + cmafec_free(); + cma_free(); + + for (;;) { + struct call *pcall = remove_and_return_a_call(); + if (!pcall) { + break; + } + + free(pcall); + } + + for (i = 0; i < agents.entries_used; i++) { + struct my_agent *agent = &agents.entries[i]; + + free_timer(agent->stats.network_wall_timer); + } +} + +/*********************************************************************** + Registers an agent. +***********************************************************************/ +void register_agent(const struct agent *agent) +{ + struct my_agent *priv_agent = &agents.entries[agents.entries_used]; + + assert(agents.entries_used < MAX_AGENTS); + assert(agent->level > 0); + + memcpy(&priv_agent->agent, agent, sizeof(struct agent)); + + priv_agent->first_outstanding_request_id = 0; + priv_agent->last_outstanding_request_id = 0; + + priv_agent->stats.network_wall_timer = new_timer(TIMER_USER, TIMER_ACTIVE); + priv_agent->stats.wait_at_network = 0; + priv_agent->stats.wait_at_network_requests = 0; + + agents.entries_used++; } /*********************************************************************** Index: client/agents/agents.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/agents.h,v retrieving revision 1.4 diff -u -r1.4 agents.h --- client/agents/agents.h 2002/06/07 16:11:24 1.4 +++ client/agents/agents.h 2002/08/20 14:48:04 @@ -41,6 +41,7 @@ }; void agents_init(void); +void agents_free(void); void register_agent(const struct agent *agent); bool agents_busy(void); Index: client/agents/cma_core.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v retrieving revision 1.27 diff -u -r1.27 cma_core.c --- client/agents/cma_core.c 2002/06/29 18:35:04 1.27 +++ client/agents/cma_core.c 2002/08/20 14:48:05 @@ -1867,6 +1867,13 @@ register_agent(&self); } +void cma_free(void) +{ + free_timer(stats.wall_timer); + free(cache2.secondary_stats); + free(cache2.city_status); +} + /**************************************************************************** ... *****************************************************************************/ Index: client/agents/cma_core.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.h,v retrieving revision 1.3 diff -u -r1.3 cma_core.h --- client/agents/cma_core.h 2002/05/08 06:09:36 1.3 +++ client/agents/cma_core.h 2002/08/20 14:48:05 @@ -64,6 +64,8 @@ */ void cma_init(void); +void cma_free(void); + /* * Will try to meet the requirements and fill out the result. Caller * should test result->found_a_valid. cma_query_result will not change Index: client/agents/cma_fec.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v retrieving revision 1.9 diff -u -r1.9 cma_fec.c --- client/agents/cma_fec.c 2002/06/13 22:43:21 1.9 +++ client/agents/cma_fec.c 2002/08/20 14:48:05 @@ -86,6 +86,16 @@ } /************************************************************************** + ... +**************************************************************************/ +void cmafec_free(void) +{ + while (cmafec_preset_num() > 0) { + cmafec_preset_remove(0); + } +} + +/************************************************************************** Sets the front-end parameter. **************************************************************************/ void cmafec_set_fe_parameter(struct city *pcity, @@ -161,6 +171,9 @@ ppreset = preset_list_get(&preset_list, index); preset_list_unlink(&preset_list, ppreset); + + free(ppreset->descr); + free(ppreset); } /************************************************************************** Index: client/agents/cma_fec.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.h,v retrieving revision 1.2 diff -u -r1.2 cma_fec.h --- client/agents/cma_fec.h 2002/06/13 22:43:22 1.2 +++ client/agents/cma_fec.h 2002/08/20 14:48:05 @@ -17,6 +17,7 @@ #include "cma_core.h" void cmafec_init(void); +void cmafec_free(void); void cmafec_set_fe_parameter(struct city *pcity, const struct cma_parameter *const parameter); Index: client/gui-gtk/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v retrieving revision 1.142 diff -u -r1.142 citydlg.c --- client/gui-gtk/citydlg.c 2002/08/07 11:21:40 1.142 +++ client/gui-gtk/citydlg.c 2002/08/20 14:48:08 @@ -3449,6 +3449,8 @@ if(pdialog->wl_editor->changed){ commit_worklist(pdialog->wl_editor); } + + close_worklist_editor(pdialog->wl_editor); close_happiness_dialog(pdialog->pcity); close_cma_dialog(pdialog->pcity); } Index: client/gui-gtk/colors.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/colors.c,v retrieving revision 1.9 diff -u -r1.9 colors.c --- client/gui-gtk/colors.c 2002/02/09 09:27:53 1.9 +++ client/gui-gtk/colors.c 2002/08/20 14:48:08 @@ -109,3 +109,15 @@ { alloc_standard_colors(); } + +/************************************************************* +... +*************************************************************/ +void free_color_system(void) +{ + int i; + + for (i = 0; i < COLOR_STD_LAST; i++) { + free(colors_standard[i]); + } +} Index: client/gui-gtk/dialogs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v retrieving revision 1.104 diff -u -r1.104 dialogs.c --- client/gui-gtk/dialogs.c 2002/08/07 11:21:41 1.104 +++ client/gui-gtk/dialogs.c 2002/08/20 14:48:09 @@ -1791,6 +1791,7 @@ races_dialog_shell = NULL; g_list_free(sorted_races_list); sorted_races_list = NULL; + free(races_toggles); } /* else there is no dialog shell to destroy */ } Index: client/gui-gtk/graphics.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/graphics.c,v retrieving revision 1.41 diff -u -r1.41 graphics.c --- client/gui-gtk/graphics.c 2002/08/07 11:21:41 1.41 +++ client/gui-gtk/graphics.c 2002/08/20 14:48:09 @@ -342,7 +342,7 @@ mysprite->width = w; mysprite->height = h; - gdk_imlib_destroy_image (im); + gdk_imlib_kill_image (im); return mysprite; } Index: client/gui-gtk/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v retrieving revision 1.113 diff -u -r1.113 gui_main.c --- client/gui-gtk/gui_main.c 2002/08/13 23:18:48 1.113 +++ client/gui-gtk/gui_main.c 2002/08/20 14:48:10 @@ -895,6 +895,9 @@ set_client_state(CLIENT_PRE_GAME_STATE); gtk_main(); + + free_color_system(); + tilespec_free_tiles(); } /************************************************************************** Index: client/gui-gtk/wldlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/wldlg.c,v retrieving revision 1.29 diff -u -r1.29 wldlg.c --- client/gui-gtk/wldlg.c 2002/07/24 10:41:56 1.29 +++ client/gui-gtk/wldlg.c 2002/08/20 14:48:11 @@ -516,6 +516,12 @@ return peditor; } +void close_worklist_editor(struct worklist_editor *peditor) +{ + gtk_widget_destroy(peditor->shell); + free(peditor); +} + /*****************************************************************/ /**** callbacks and functions for the global worklists report ****/ /**************************************************************** Index: client/gui-gtk/wldlg.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/wldlg.h,v retrieving revision 1.4 diff -u -r1.4 wldlg.h --- client/gui-gtk/wldlg.h 2002/02/07 10:24:18 1.4 +++ client/gui-gtk/wldlg.h 2002/08/20 14:48:11 @@ -63,6 +63,7 @@ WorklistCancelCallback cancel_cb, int embedded_in_city); +void close_worklist_editor(struct worklist_editor *peditor); GtkWidget *popup_worklist(struct worklist *pwl, struct city *pcity, GtkWidget * parent, void *user_data, Index: client/include/colors_g.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/include/colors_g.h,v retrieving revision 1.4 diff -u -r1.4 colors_g.h --- client/include/colors_g.h 2002/06/15 16:54:42 1.4 +++ client/include/colors_g.h 2002/08/20 14:48:11 @@ -33,6 +33,7 @@ enum Display_color_type get_visual(void); void init_color_system(void); +void free_color_system(void); void color_error(void); #endif /* FC__COLORS_G_H */ Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.146 diff -u -r1.146 game.c --- common/game.c 2002/08/19 23:05:30 1.146 +++ common/game.c 2002/08/20 14:48:12 @@ -19,6 +19,7 @@ #include #include "assert.h" +#include "capstr.h" #include "city.h" #include "connection.h" #include "fcintl.h" @@ -741,7 +742,12 @@ game.load_options.load_starts = TRUE; game.load_options.load_private_map = TRUE; game.load_options.load_settings = TRUE; - + + conn_list_init(&game.all_connections); + conn_list_init(&game.est_connections); + conn_list_init(&game.game_connections); + + init_our_capability(); map_init(); idex_init(); Index: server/maphand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v retrieving revision 1.106 diff -u -r1.106 maphand.c --- server/maphand.c 2002/08/19 20:53:36 1.106 +++ server/maphand.c 2002/08/20 14:48:15 @@ -916,6 +916,27 @@ } /*************************************************************** + frees a player's private map. +***************************************************************/ +void player_map_free(struct player *pplayer) +{ + if (!pplayer->private_map) { + return; + } + + whole_map_iterate(x, y) { + struct player_tile *plrtile = map_get_player_tile(x, y, pplayer); + + if (plrtile->city) { + free(plrtile->city); + } + } whole_map_iterate_end; + + free(pplayer->private_map); + pplayer->private_map = NULL; +} + +/*************************************************************** We need to use use fogofwar_old here, so the player's tiles get in the same state as the other players' tiles. ***************************************************************/ Index: server/maphand.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/maphand.h,v retrieving revision 1.28 diff -u -r1.28 maphand.h --- server/maphand.h 2002/02/27 10:06:41 1.28 +++ server/maphand.h 2002/08/20 14:48:15 @@ -71,7 +71,9 @@ void map_know_all(struct player *pplayer); void map_know_and_see_all(struct player *pplayer); void show_map_to_all(void); + void player_map_allocate(struct player *pplayer); +void player_map_free(struct player *pplayer); struct player_tile *map_get_player_tile(int x, int y, struct player *pplayer); void update_tile_knowledge(struct player *pplayer,int x, int y); Index: server/plrhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v retrieving revision 1.242 diff -u -r1.242 plrhand.c --- server/plrhand.c 2002/08/10 17:07:28 1.242 +++ server/plrhand.c 2002/08/20 14:48:16 @@ -1829,24 +1829,3 @@ { send_attribute_block(pplayer, pplayer->current_conn); } - -/*************************************************************** - frees a player's private map. -***************************************************************/ -void player_map_free(struct player *pplayer) -{ - struct player_tile *plrtile; - - if (!pplayer->private_map) return; - - whole_map_iterate(x, y) { - plrtile = map_get_player_tile(x, y, pplayer); - if (plrtile->city) { - free(plrtile->city); - } - } whole_map_iterate_end; - - free(pplayer->private_map); - pplayer->private_map = NULL; -} - Index: server/plrhand.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v retrieving revision 1.47 diff -u -r1.47 plrhand.h --- server/plrhand.h 2002/08/06 22:27:02 1.47 +++ server/plrhand.h 2002/08/20 14:48:16 @@ -101,6 +101,4 @@ enum plr_info_level player_info_level(struct player *plr, struct player *receiver); -void player_map_free(struct player *pplayer); - #endif /* FC__PLRHAND_H */ Index: server/sernet.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v retrieving revision 1.94 diff -u -r1.94 sernet.c --- server/sernet.c 2002/08/06 22:27:03 1.94 +++ server/sernet.c 2002/08/20 14:48:17 @@ -769,10 +769,6 @@ { int i; - conn_list_init(&game.all_connections); - conn_list_init(&game.est_connections); - conn_list_init(&game.game_connections); - for(i=0; iused = FALSE; Index: server/srv_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v retrieving revision 1.90 diff -u -r1.90 srv_main.c --- server/srv_main.c 2002/08/19 23:05:35 1.90 +++ server/srv_main.c 2002/08/20 14:48:19 @@ -1783,7 +1783,6 @@ con_flush(); - init_our_capability(); game_init(); /* load a saved game */ @@ -1978,5 +1977,14 @@ } close_connections_and_socket(); + server_game_free(); +} + +void server_game_free() +{ + players_iterate(pplayer) { + player_map_free(pplayer); + } players_iterate_end; + nation_city_names_free(misc_city_names); game_free(); } Index: server/srv_main.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.h,v retrieving revision 1.11 diff -u -r1.11 srv_main.h --- server/srv_main.h 2002/05/25 17:44:09 1.11 +++ server/srv_main.h 2002/08/20 14:48:19 @@ -54,6 +54,7 @@ bool is_id_allocated(int id); void alloc_id(int id); int get_next_id_number(void); +void server_game_free(void); extern struct server_arguments srvarg; Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.243 diff -u -r1.243 stdinhand.c --- server/stdinhand.c 2002/08/15 09:56:01 1.243 +++ server/stdinhand.c 2002/08/20 14:48:22 @@ -2909,13 +2909,9 @@ cmd_reply(CMD_LOAD, caller, C_COMMENT, _("Loading saved game: %s..."), arg); /* we found it, free all structures */ - - players_iterate(pplayer) { - player_map_free(pplayer); - } players_iterate_end; - + server_game_free(); game_free(); - nation_city_names_free(misc_city_names); + game_init(); loadtimer = new_timer_start(TIMER_CPU, TIMER_ACTIVE);