<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40546 >

Attached patch makes genlist_free free all memory allocated
by the list before freeing itself. Also, genlist_unlink_all
is renamed to genlist_clear.

The rest of the patch is a removal of all the *_unlink_all
calls in places of the form

  foo_list_unlink_all(list);
  foo_list_free(list);


This makes genlist_free a proper opposite of genlist_new,
prevents the programming error of forgetting to free
the list nodes before freeing the list, and reduces the
total number of source code lines.


-----------------------------------------------------------------------
遠浅まで自転車で十日かかると思います。
 client/chatline_common.c         |    2 +-
 client/citydlg_common.c          |    1 -
 client/control.c                 |    4 ++--
 client/goto.c                    |    3 +--
 client/gui-ftwl/mapview.c        |    5 ++---
 client/gui-gtk-2.0/citydlg.c     |    5 ++---
 client/gui-gtk-2.0/pages.c       |    3 ---
 client/gui-sdl/chatline.c        |    2 --
 client/gui-sdl/citydlg.c         |   14 +++++++-------
 client/gui-sdl/gui_main.c        |    1 -
 client/gui-win32/graphics.c      |   10 ++--------
 client/gui-win32/gui_main.c      |    3 +--
 client/gui-xaw/citydlg.c         |    4 ++--
 client/helpdata.c                |    3 +--
 client/mapview_common.c          |    1 -
 client/packhand.c                |    7 +++----
 client/servers.c                 |    1 -
 client/text.c                    |    2 --
 common/diptreaty.c               |    1 -
 common/effects.c                 |    6 ------
 common/game.c                    |    3 ---
 common/map.c                     |    1 -
 server/citytools.c               |    4 +---
 server/cityturn.c                |    1 -
 server/diplhand.c                |    2 +-
 server/scripting/script_signal.c |    1 -
 server/sernet.c                  |    1 -
 server/stdinhand.c               |    5 +----
 server/techtools.c               |    1 -
 server/unittools.c               |    4 ----
 utility/ftwl/widget_window.c     |    3 +--
 utility/genlist.c                |    8 ++++++--
 utility/genlist.h                |    4 ++--
 utility/registry.c               |    2 --
 utility/speclist.h               |    7 ++++---
 35 files changed, 40 insertions(+), 85 deletions(-)

diff --git a/client/chatline_common.c b/client/chatline_common.c
index 5f03a7f..7d69645 100644
--- a/client/chatline_common.c
+++ b/client/chatline_common.c
@@ -116,7 +116,7 @@ void output_window_thaw()
       free(pline->text);
       free(pline);
     } remaining_list_iterate_end;
-    remaining_list_unlink_all(remains);
+    remaining_list_clear(remains);
   }
 }
 
diff --git a/client/citydlg_common.c b/client/citydlg_common.c
index 57bc524..48e080c 100644
--- a/client/citydlg_common.c
+++ b/client/citydlg_common.c
@@ -458,7 +458,6 @@ void get_city_dialog_output_text(const struct city *pcity,
 		     peffect->value);
 	total = new_total;
       } effect_list_iterate_end;
-      effect_list_unlink_all(plist);
       effect_list_free(plist);
     }
   }
diff --git a/client/control.c b/client/control.c
index c655548..4a0b079 100644
--- a/client/control.c
+++ b/client/control.c
@@ -151,7 +151,7 @@ int get_num_units_in_focus(void)
 static void store_previous_focus(void)
 {
   if (get_num_units_in_focus() > 0) {
-    unit_list_unlink_all(previous_focus);
+    unit_list_clear(previous_focus);
     unit_list_iterate(get_units_in_focus(), punit) {
       unit_list_append(previous_focus, punit);
     } unit_list_iterate_end;
@@ -354,7 +354,7 @@ void set_unit_focus(struct unit *punit)
   unit_list_iterate(current_focus, punit_old) {
     refresh_unit_mapcanvas(punit_old, punit_old->tile, TRUE, FALSE);
   } unit_list_iterate_end;
-  unit_list_unlink_all(current_focus);
+  unit_list_clear(current_focus);
 
   if (!can_client_change_view()) {
     /* This function can be called to set the focus to NULL when
diff --git a/client/goto.c b/client/goto.c
index c2485a7..4cb4494 100644
--- a/client/goto.c
+++ b/client/goto.c
@@ -158,7 +158,6 @@ void free_client_goto(void)
     goto_map_list_iterate(goto_maps, goto_map) {
       goto_map_free(goto_map);
     } goto_map_list_iterate_end;
-    goto_map_list_unlink_all(goto_maps);
     goto_map_list_free(goto_maps);
     goto_maps = NULL;
   }
@@ -833,7 +832,7 @@ void exit_goto_state(void)
   goto_map_list_iterate(goto_maps, goto_map) {
     goto_map_free(goto_map);
   } goto_map_list_iterate_end;
-  goto_map_list_unlink_all(goto_maps);
+  goto_map_list_clear(goto_maps);
 
   goto_destination = NULL;
 }
diff --git a/client/gui-ftwl/mapview.c b/client/gui-ftwl/mapview.c
index 73f72c1..536a22a 100644
--- a/client/gui-ftwl/mapview.c
+++ b/client/gui-ftwl/mapview.c
@@ -494,7 +494,7 @@ void flush_dirty(void)
     region_list_iterate(region_list, region) {
       free(region);
     } region_list_iterate_end;
-    region_list_unlink_all(region_list);
+    region_list_clear(region_list);
     
     flush_mapcanvas(0, 0, mapview.width, mapview.height);
     all_dirty = FALSE;
@@ -503,7 +503,7 @@ void flush_dirty(void)
       flush_mapcanvas(region->x, region->y, region->width, region->height);
       free(region);
     } region_list_iterate_end;
-    region_list_unlink_all(region_list);
+    region_list_clear(region_list);
   }
   sw_paint_all();
 }
@@ -1293,7 +1293,6 @@ void popdown_mapcanvas(void)
   region_list_iterate(region_list, region) {
     free(region);
   } region_list_iterate_end;
-  region_list_unlink_all(region_list);
   region_list_free(region_list);
   
   te_destroy_screen(screen);
diff --git a/client/gui-gtk-2.0/citydlg.c b/client/gui-gtk-2.0/citydlg.c
index 03f68ba..94fab4c 100644
--- a/client/gui-gtk-2.0/citydlg.c
+++ b/client/gui-gtk-2.0/citydlg.c
@@ -2367,7 +2367,6 @@ static void unit_upgrade_callback(GtkWidget *w, gpointer data)
   punits = unit_list_new();
   unit_list_append(punits, punit);
   popup_upgrade_dialog(punits);
-  unit_list_unlink_all(punits);
   unit_list_free(punits);
 }
 
@@ -2793,14 +2792,14 @@ static void city_destroy_callback(GtkWidget *w, gpointer data)
   }
   unit_list_iterate_end;
 
-  unit_list_unlink_all(pdialog->pcity->info_units_supported);
+  unit_list_clear(pdialog->pcity->info_units_supported);
 
   unit_list_iterate(pdialog->pcity->info_units_present, psunit) {
     free(psunit);
   }
   unit_list_iterate_end;
 
-  unit_list_unlink_all(pdialog->pcity->info_units_present);
+  unit_list_clear(pdialog->pcity->info_units_present);
 
   free(pdialog);
 
diff --git a/client/gui-gtk-2.0/pages.c b/client/gui-gtk-2.0/pages.c
index f251ac7..095b7e9 100644
--- a/client/gui-gtk-2.0/pages.c
+++ b/client/gui-gtk-2.0/pages.c
@@ -1674,7 +1674,6 @@ static void update_saves_store(GtkListStore *store)
     free(pfile);
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 
   files = datafilelist_infix(NULL, ".sav", FALSE);
@@ -1690,7 +1689,6 @@ static void update_saves_store(GtkListStore *store)
     free(pfile);
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 }
 
@@ -1868,7 +1866,6 @@ static void update_scenario_page(void)
     free(pfile);
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 }
 
diff --git a/client/gui-sdl/chatline.c b/client/gui-sdl/chatline.c
index 0e8085a..716f7cf 100644
--- a/client/gui-sdl/chatline.c
+++ b/client/gui-sdl/chatline.c
@@ -246,7 +246,6 @@ static void popup_load_game_dialog(void)
     free(pfile);
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 
   files = datafilelist_infix(NULL, ".sav", FALSE);
@@ -284,7 +283,6 @@ static void popup_load_game_dialog(void)
     free(pfile);
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 
   pLastLabel = pFilenameLabel;
diff --git a/client/gui-sdl/citydlg.c b/client/gui-sdl/citydlg.c
index 03433f5..5881eaa 100644
--- a/client/gui-sdl/citydlg.c
+++ b/client/gui-sdl/citydlg.c
@@ -2209,7 +2209,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
           FREESURFACE(pTmp);            
         } effect_list_iterate_end;
         
-        effect_list_unlink_all(sources);
+        effect_list_clear(sources);
 
 	dest.y = i;        
         
@@ -2307,7 +2307,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
              
         } effect_list_iterate_end;
 
-        effect_list_unlink_all(sources);
+        effect_list_clear(sources);
 
         get_city_bonus_effects(sources, pCity, NULL, EFT_FORCE_CONTENT);
         
@@ -2325,7 +2325,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
              
         } effect_list_iterate_end;
 
-        effect_list_unlink_all(sources);
+        effect_list_clear(sources);
 
         get_city_bonus_effects(sources, pCity, NULL, EFT_NO_UNHAPPY);
 
@@ -2340,7 +2340,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
 
         } effect_list_iterate_end;
 
-        effect_list_unlink_all(sources);
+        effect_list_clear(sources);
 
         
 	dest.x = pCityWindow->size.x + adj_size(187) - pSurf->w - adj_size(2);
@@ -2362,7 +2362,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
           FREESURFACE(pTmp);            
           
         } effect_list_iterate_end;
-        effect_list_unlink_all(sources);        
+        effect_list_clear(sources);        
 
         get_city_bonus_effects(sources, pCity, NULL, EFT_FORCE_CONTENT);        
 
@@ -2377,7 +2377,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
           FREESURFACE(pTmp);            
           
         } effect_list_iterate_end;
-        effect_list_unlink_all(sources);        
+        effect_list_clear(sources);        
 
         get_city_bonus_effects(sources, pCity, NULL, EFT_NO_UNHAPPY);        
 
@@ -2392,7 +2392,7 @@ static void redraw_happyness_city_dialog(const struct widget *pCityWindow,
           FREESURFACE(pTmp);            
           
         } effect_list_iterate_end;
-        effect_list_unlink_all(sources);
+        effect_list_clear(sources);
         
 	dest.y = i;        
 
diff --git a/client/gui-sdl/gui_main.c b/client/gui-sdl/gui_main.c
index 803e8b0..05a5d74 100644
--- a/client/gui-sdl/gui_main.c
+++ b/client/gui-sdl/gui_main.c
@@ -1027,7 +1027,6 @@ void ui_exit()
   diplomacy_dialog_done();
   intel_dialog_done();  
 
-  callback_list_unlink_all(callbacks);
   callback_list_free(callbacks);
   
   unload_cursors();
diff --git a/client/gui-win32/graphics.c b/client/gui-win32/graphics.c
index 7f04f41..5404f47 100644
--- a/client/gui-win32/graphics.c
+++ b/client/gui-win32/graphics.c
@@ -309,10 +309,7 @@ static void flush_hbmp_cache()
     crect_list_iterate(free_rects, pcrect) {
       free(pcrect);
     } crect_list_iterate_end;
-
-    crect_list_unlink_all(free_rects);
-
-    free(free_rects);
+    crect_list_free(free_rects);
   }
 
   free_rects = crect_list_new();
@@ -322,10 +319,7 @@ static void flush_hbmp_cache()
     crect_list_iterate(used_rects, pcrect) {
       free(pcrect);
     } crect_list_iterate_end;
-
-    crect_list_unlink_all(used_rects);
-
-    free(used_rects);
+    crect_list_free(used_rects);
   }
 
   used_rects = crect_list_new();
diff --git a/client/gui-win32/gui_main.c b/client/gui-win32/gui_main.c
index 05e63be..0441edb 100644
--- a/client/gui-win32/gui_main.c
+++ b/client/gui-win32/gui_main.c
@@ -809,8 +809,7 @@ ui_main(int argc, char *argv[])
 
   free_timer(anim_timer);
   free_timer(callback_timer);
-  callback_list_unlink_all(callbacks);
-  free(callbacks);
+  callback_list_free(callbacks);
 
   FreeLibrary(hmsimg32);
 }
diff --git a/client/gui-xaw/citydlg.c b/client/gui-xaw/citydlg.c
index 15dfe5f..c3d6b06 100644
--- a/client/gui-xaw/citydlg.c
+++ b/client/gui-xaw/citydlg.c
@@ -2333,11 +2333,11 @@ void close_city_dialog(struct city_dialog *pdialog)
   unit_list_iterate(pdialog->pcity->info_units_supported, psunit) {
     free(psunit);
   } unit_list_iterate_end;
-  unit_list_unlink_all(pdialog->pcity->info_units_supported);
+  unit_list_clear(pdialog->pcity->info_units_supported);
   unit_list_iterate(pdialog->pcity->info_units_present, psunit) {
     free(psunit);
   } unit_list_iterate_end;
-  unit_list_unlink_all(pdialog->pcity->info_units_present);
+  unit_list_clear(pdialog->pcity->info_units_present);
 
 /*
   if(pdialog->is_modal)
diff --git a/client/helpdata.c b/client/helpdata.c
index dbb1515..7920a58 100644
--- a/client/helpdata.c
+++ b/client/helpdata.c
@@ -113,7 +113,7 @@ void free_help_texts(void)
     free(ptmp->text);
     free(ptmp);
   } help_list_iterate_end;
-  help_list_unlink_all(help_nodes);
+  help_list_clear(help_nodes);
 }
 
 /****************************************************************************
@@ -496,7 +496,6 @@ void boot_help_texts(struct player *pplayer)
 	help_list_iterate(category_nodes, ptmp) {
 	  help_list_append(help_nodes, ptmp);
 	} help_list_iterate_end;
-	help_list_unlink_all(category_nodes);
         help_list_free(category_nodes);
 	continue;
       }
diff --git a/client/mapview_common.c b/client/mapview_common.c
index 377004c..880a487 100644
--- a/client/mapview_common.c
+++ b/client/mapview_common.c
@@ -2286,7 +2286,6 @@ void unqueue_mapview_updates(bool write_to_screen)
   }
   for (i = 0; i < TILE_UPDATE_COUNT; i++) {
     if (my_tile_updates[i]) {
-      tile_list_unlink_all(my_tile_updates[i]);
       tile_list_free(my_tile_updates[i]);
     }
   }
diff --git a/client/packhand.c b/client/packhand.c
index a221497..e4ce6db 100644
--- a/client/packhand.c
+++ b/client/packhand.c
@@ -97,7 +97,6 @@ void packhand_free(void)
       destroy_city_virtual(pcity);
     } city_list_iterate_end;
 
-    city_list_unlink_all(invisible_cities);
     city_list_free(invisible_cities);
     invisible_cities = NULL;
   }
@@ -1514,11 +1513,11 @@ void handle_unit_short_info(struct packet_unit_short_info *packet)
       unit_list_iterate(pcity->info_units_supported, psunit) {
 	destroy_unit_virtual(psunit);
       } unit_list_iterate_end;
-      unit_list_unlink_all(pcity->info_units_supported);
+      unit_list_clear(pcity->info_units_supported);
       unit_list_iterate(pcity->info_units_present, ppunit) {
 	destroy_unit_virtual(ppunit);
       } unit_list_iterate_end;
-      unit_list_unlink_all(pcity->info_units_present);
+      unit_list_clear(pcity->info_units_present);
     }
 
     /* Okay, append a unit struct to the proper list. */
@@ -2435,7 +2434,7 @@ void handle_tile_info(struct packet_tile_info *packet)
               player_name(unit_owner(punit)));
     } unit_list_iterate_end;
     assert(unit_list_size(ptile->units) == 0);
-    unit_list_unlink_all(ptile->units);
+    unit_list_clear(ptile->units);
   }
 
   ptile->continent = packet->continent;
diff --git a/client/servers.c b/client/servers.c
index fe1f93f..1319b77 100644
--- a/client/servers.c
+++ b/client/servers.c
@@ -521,7 +521,6 @@ static void delete_server_list(struct server_list *server_list)
     free(ptmp);
   } server_list_iterate_end;
 
-  server_list_unlink_all(server_list);
   server_list_free(server_list);
 }
 
diff --git a/client/text.c b/client/text.c
index 04b7dae..e50a758 100644
--- a/client/text.c
+++ b/client/text.c
@@ -1210,7 +1210,6 @@ const char *text_happiness_buildings(const struct city *pcity)
       astr_add(&str, "%s", buf);
     }
   } effect_list_iterate_end;
-  effect_list_unlink_all(plist);
   effect_list_free(plist);
 
   if (faces == 0) {
@@ -1249,7 +1248,6 @@ const char *text_happiness_wonders(const struct city *pcity)
     }
   } effect_list_iterate_end;
 
-  effect_list_unlink_all(plist);
   effect_list_free(plist);
 
   if (faces == 0) {
diff --git a/common/diptreaty.c b/common/diptreaty.c
index cf34c7f..9eb2e2f 100644
--- a/common/diptreaty.c
+++ b/common/diptreaty.c
@@ -91,7 +91,6 @@ void clear_treaty(struct Treaty *ptreaty)
   clause_list_iterate(ptreaty->clauses, pclause) {
     free(pclause);
   } clause_list_iterate_end;
-  clause_list_unlink_all(ptreaty->clauses);
   clause_list_free(ptreaty->clauses);
 }
 
diff --git a/common/effects.c b/common/effects.c
index caada50..44420e3 100644
--- a/common/effects.c
+++ b/common/effects.c
@@ -300,13 +300,11 @@ static void effect_free(struct effect *peffect)
   requirement_list_iterate(peffect->reqs, preq) {
     free(preq);
   } requirement_list_iterate_end;
-  requirement_list_unlink_all(peffect->reqs);
   requirement_list_free(peffect->reqs);
 
   requirement_list_iterate(peffect->nreqs, preq) {
     free(preq);
   } requirement_list_iterate_end;
-  requirement_list_unlink_all(peffect->nreqs);
   requirement_list_free(peffect->nreqs);
 
   free(peffect);
@@ -376,7 +374,6 @@ void ruleset_cache_free(void)
     effect_list_iterate(plist, peffect) {
       effect_free(peffect);
     } effect_list_iterate_end;
-    effect_list_unlink_all(plist);
     effect_list_free(plist);
     ruleset_cache.tracker = NULL;
   }
@@ -385,7 +382,6 @@ void ruleset_cache_free(void)
     struct effect_list *plist = ruleset_cache.effects[i];
 
     if (plist) {
-      effect_list_unlink_all(plist);
       effect_list_free(plist);
       ruleset_cache.effects[i] = NULL;
     }
@@ -395,7 +391,6 @@ void ruleset_cache_free(void)
     struct effect_list *plist = ruleset_cache.reqs.buildings[i];
 
     if (plist) {
-      effect_list_unlink_all(plist);
       effect_list_free(plist);
       ruleset_cache.reqs.buildings[i] = NULL;
     }
@@ -405,7 +400,6 @@ void ruleset_cache_free(void)
     struct effect_list *plist = ruleset_cache.reqs.govs[i];
 
     if (plist) {
-      effect_list_unlink_all(plist);
       effect_list_free(plist);
       ruleset_cache.reqs.govs[i] = NULL;
     }
diff --git a/common/game.c b/common/game.c
index b1004ce..f0d4378 100644
--- a/common/game.c
+++ b/common/game.c
@@ -550,7 +550,6 @@ void game_remove_player(struct player *pplayer)
    * the caller to fix them.  This happens when /loading a game while a
    * client is connected. */
 #endif
-  conn_list_unlink_all(pplayer->connections);
   conn_list_free(pplayer->connections);
   pplayer->connections = NULL;
 
@@ -562,7 +561,6 @@ void game_remove_player(struct player *pplayer)
             unit_list_size(pplayer->units),
             nation_rule_name(nation_of_player(pplayer)));
   }
-  unit_list_unlink_all(pplayer->units);
   unit_list_free(pplayer->units);
   pplayer->units = NULL;
 
@@ -574,7 +572,6 @@ void game_remove_player(struct player *pplayer)
             city_list_size(pplayer->cities),
             nation_rule_name(nation_of_player(pplayer)));
   }
-  city_list_unlink_all(pplayer->cities);
   city_list_free(pplayer->cities);
   pplayer->cities = NULL;
 
diff --git a/common/map.c b/common/map.c
index d13df47..8d15d77 100644
--- a/common/map.c
+++ b/common/map.c
@@ -381,7 +381,6 @@ struct tile *index_to_tile(int index)
 ***************************************************************/
 static void tile_free(struct tile *ptile)
 {
-  unit_list_unlink_all(ptile->units);
   unit_list_free(ptile->units);
   if (ptile->spec_sprite) {
     free(ptile->spec_sprite);
diff --git a/server/citytools.c b/server/citytools.c
index d422460..582914a 100644
--- a/server/citytools.c
+++ b/server/citytools.c
@@ -152,7 +152,6 @@ void city_thaw_workers_queue(void)
     city_thaw_workers(pcity);
   } city_list_iterate_end;
 
-  city_list_unlink_all(arrange_workers_queue);
   city_list_free(arrange_workers_queue);
   arrange_workers_queue = NULL;
 }
@@ -854,7 +853,7 @@ void transfer_city(struct player *ptaker, struct city *pcity,
     punit->homecity = 0;
     send_unit_info(NULL, punit);
   } unit_list_iterate_end;
-  unit_list_unlink_all(pcity->units_supported);
+  unit_list_clear(pcity->units_supported);
 
   /* Remove all global improvement effects that this city confers (but
      then restore the local improvement list - we need this to restore the
@@ -908,7 +907,6 @@ void transfer_city(struct player *ptaker, struct city *pcity,
 		      pcity, NULL,
 		      kill_outside, transfer_unit_verbose);
   /* The units themselves are allready freed by transfer_city_units. */
-  unit_list_unlink_all(old_city_units);
   unit_list_free(old_city_units);
 
   if (resolve_stack) {
diff --git a/server/cityturn.c b/server/cityturn.c
index eef5b31..b860a5e 100644
--- a/server/cityturn.c
+++ b/server/cityturn.c
@@ -150,7 +150,6 @@ void city_refresh_queue_processing(void)
     }
   } city_list_iterate_end;
 
-  city_list_unlink_all(city_refresh_queue);
   city_list_free(city_refresh_queue);
   city_refresh_queue = NULL;
 }
diff --git a/server/diplhand.c b/server/diplhand.c
index 6b70bca..974a8d2 100644
--- a/server/diplhand.c
+++ b/server/diplhand.c
@@ -86,7 +86,7 @@ void free_treaties(void)
     free(pt);
   } treaty_list_iterate_end;
 
-  treaty_list_unlink_all(treaties);
+  treaty_list_clear(treaties);
 }
 
 /**************************************************************************
diff --git a/server/scripting/script_signal.c b/server/scripting/script_signal.c
index 058cb91..db69f05 100644
--- a/server/scripting/script_signal.c
+++ b/server/scripting/script_signal.c
@@ -227,7 +227,6 @@ static void internal_signal_free(const char *signal_name)
       internal_signal_callback_remove(signal->callbacks, pcallback);
     } signal_callback_list_iterate_end;
 
-    signal_callback_list_unlink_all(signal->callbacks);
     signal_callback_list_free(signal->callbacks);
     free(signal);
   } else {
diff --git a/server/sernet.c b/server/sernet.c
index c0b2919..fe56b5f 100644
--- a/server/sernet.c
+++ b/server/sernet.c
@@ -229,7 +229,6 @@ void close_connections_and_socket(void)
     if(connections[i].used) {
       close_connection(&connections[i]);
     }
-    conn_list_unlink_all(connections[i].self);
     conn_list_free(connections[i].self);
   }
 
diff --git a/server/stdinhand.c b/server/stdinhand.c
index dd97aab..e9de673 100644
--- a/server/stdinhand.c
+++ b/server/stdinhand.c
@@ -390,7 +390,6 @@ static void free_vote(struct vote *pvote)
     vote_cast_list_iterate(pvote->votes_cast, pvc) {
       free(pvc);
     } vote_cast_list_iterate_end;
-    vote_cast_list_unlink_all(pvote->votes_cast);
     vote_cast_list_free(pvote->votes_cast);
     pvote->votes_cast = NULL;
   }
@@ -429,7 +428,7 @@ void clear_all_votes(void)
   vote_list_iterate(vote_list, pvote) {
     free_vote(pvote);
   } vote_list_iterate_end;
-  vote_list_unlink_all(vote_list);
+  vote_list_clear(vote_list);
 }
 
 /**************************************************************************
@@ -4807,7 +4806,6 @@ static void show_scenarios(struct connection *caller)
     free(pfile);
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 
   files = datafilelist_infix(NULL, ".sav", TRUE);
@@ -4821,7 +4819,6 @@ static void show_scenarios(struct connection *caller)
     free(pfile); 
   } datafile_list_iterate_end;
 
-  datafile_list_unlink_all(files);
   datafile_list_free(files);
 
   cmd_reply(CMD_LIST, caller, C_COMMENT, horiz_line);
diff --git a/server/techtools.c b/server/techtools.c
index 89dae33..7075544 100644
--- a/server/techtools.c
+++ b/server/techtools.c
@@ -184,7 +184,6 @@ void do_tech_parasite_effect(struct player *pplayer)
       }
     } advance_index_iterate_end;
   }
-  effect_list_unlink_all(plist);
   effect_list_free(plist);
 }
 
diff --git a/server/unittools.c b/server/unittools.c
index fb59e3e..1ef4a39 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -263,7 +263,6 @@ static void do_upgrade_effects(struct player *pplayer)
     upgrades--;
   }
 
-  unit_list_unlink_all(candidates);
   unit_list_free(candidates);
 }
 
@@ -2489,13 +2488,11 @@ static bool unit_survive_autoattack(struct unit *punit)
     if (game_find_unit_by_number(sanity1)) {
       send_unit_info(NULL, punit);
     } else {
-      unit_list_unlink_all(autoattack);
       unit_list_free(autoattack);
       return FALSE; /* moving unit dead */
     }
   } unit_list_iterate_safe_end;
 
-  unit_list_unlink_all(autoattack);
   unit_list_free(autoattack);
   if (game_find_unit_by_number(sanity1)) {
     /* We could have lost movement in combat */
@@ -2779,7 +2776,6 @@ bool move_unit(struct unit *punit, struct tile *pdesttile, int move_cost)
 
       unit_move_consequences(pcargo, psrctile, pdesttile, TRUE);
     } unit_list_iterate_end;
-    unit_list_unlink_all(cargo_units);
     unit_list_free(cargo_units);
   }
 
diff --git a/utility/ftwl/widget_window.c b/utility/ftwl/widget_window.c
index 9a654b0..b939785 100644
--- a/utility/ftwl/widget_window.c
+++ b/utility/ftwl/widget_window.c
@@ -660,7 +660,7 @@ static void merge_regions(struct region_list *list)
 
   orig = tmp;
   copy = list;
-  region_list_unlink_all(copy);
+  region_list_clear(copy);
 
   region_list_iterate(orig, region) {
     if (ct_rect_in_rect_list(region, copy)) {
@@ -670,7 +670,6 @@ static void merge_regions(struct region_list *list)
     }
   } region_list_iterate_end;
 
-  region_list_unlink_all(tmp);
   region_list_free(tmp);
 }
 
diff --git a/utility/genlist.c b/utility/genlist.c
index 5c7e707..e827f47 100644
--- a/utility/genlist.c
+++ b/utility/genlist.c
@@ -57,10 +57,14 @@ struct genlist *genlist_copy(struct genlist *pgenlist)
 }
 
 /************************************************************************
-  Remove a genlist.  The list must be empty first!
+  Free all memory allocated by the genlist.
 ************************************************************************/
 void genlist_free(struct genlist *pgenlist)
 {
+  if (!pgenlist) {
+    return;
+  }
+  genlist_clear(pgenlist);
   free(pgenlist);
 }
 
@@ -96,7 +100,7 @@ void *genlist_get(const struct genlist *pgenlist, int idx)
   the user-data).  At the end the state of the genlist will be the
   same as when genlist_init() is called on a new genlist.
 ************************************************************************/
-void genlist_unlink_all(struct genlist *pgenlist)
+void genlist_clear(struct genlist *pgenlist)
 {
   if(pgenlist->nelements > 0) {
     struct genlist_link *plink=pgenlist->head_link, *plink2;
diff --git a/utility/genlist.h b/utility/genlist.h
index 25e5765..7090b00 100644
--- a/utility/genlist.h
+++ b/utility/genlist.h
@@ -38,7 +38,7 @@
     
   - The data structures used internally by the genlist to store
     data for the links etc.  These are allocated by genlist_insert(),
-    and freed by genlist_unlink() and genlist_unlink_all().  That is,
+    and freed by genlist_unlink() and genlist_clear().  That is,
     it is the responsibility of the user to call the unlink functions
     as necessary to avoid memory leaks.
 
@@ -74,7 +74,7 @@ int genlist_size(const struct genlist *pgenlist);
 void *genlist_get(const struct genlist *pgenlist, int idx);
 struct genlist *genlist_new(void);
 struct genlist *genlist_copy(struct genlist *pgenlist);
-void genlist_unlink_all(struct genlist *pgenlist);
+void genlist_clear(struct genlist *pgenlist);
 void genlist_free(struct genlist *pgenlist);
 void genlist_append(struct genlist *pgenlist, void *data);
 void genlist_prepend(struct genlist *pgenlist, void *data);
diff --git a/utility/registry.c b/utility/registry.c
index 8cf82a3..9ea895d 100644
--- a/utility/registry.c
+++ b/utility/registry.c
@@ -284,10 +284,8 @@ void section_file_free(struct section_file *file)
      just free the list meta-data:
   */
   section_list_iterate(file->sections, psection) {
-    entry_list_unlink_all(psection->entries);
     entry_list_free(psection->entries);
   } section_list_iterate_end;
-  section_list_unlink_all(file->sections);
   section_list_free(file->sections);
   file->sections = NULL;
 
diff --git a/utility/speclist.h b/utility/speclist.h
index ff683c7..b1c1540 100644
--- a/utility/speclist.h
+++ b/utility/speclist.h
@@ -31,12 +31,13 @@
       struct foo_list;
    and prototypes for the following functions:
       struct foolist *foo_list_new();
+      void foo_list_free(struct foo_list *This);
       int  foo_list_size(struct foo_list *This);
       foo_t *foo_list_get(struct foo_list *This, int index);
       void foo_list_prepend(struct foo_list *This, foo_t *pfoo);
       void foo_list_append(struct foo_list *This, foo_t *pfoo);
       void foo_list_unlink(struct foo_list *This, foo_t *pfoo);
-      void foo_list_unlink_all(struct foo_list *This);
+      void foo_list_clear(struct foo_list *This);
       bool foo_list_search(struct foo_list *this, foo_t *pfoo);
       void foo_list_sort(struct foo_list *This, 
          int (*compar)(const void *, const void *));
@@ -120,9 +121,9 @@ static inline void SPECLIST_FOO(_list_append) (SPECLIST_LIST *tthis, SPECLIST_TY
   genlist_append(tthis->list, pfoo);
 }
 
-static inline void SPECLIST_FOO(_list_unlink_all) (SPECLIST_LIST *tthis)
+static inline void SPECLIST_FOO(_list_clear) (SPECLIST_LIST *tthis)
 {
-  genlist_unlink_all(tthis->list);
+  genlist_clear(tthis->list);
 }
 
 static inline void SPECLIST_FOO(_list_free) (SPECLIST_LIST *tthis)
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to