Complete.Org: Mailing Lists: Archives: freeciv-dev: July 1999:
[Freeciv-Dev] xaw client Airlift/Goto dialog memory leak (PR#74)
Home

[Freeciv-Dev] xaw client Airlift/Goto dialog memory leak (PR#74)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] xaw client Airlift/Goto dialog memory leak (PR#74)
From: jjm@xxxxxxxxxxxx
Date: Sat, 24 Jul 1999 21:13:11 -0700 (PDT)

Full_Name: Jeff Mallatt
Version: 1.8.1
OS: Linux
Submission from: (NULL) (199.103.194.35)


The xaw client Airlift/Goto dialog leaks memory whenever the "All Cities"
button
is toggled.

Here's my fix.

diff -Nur freeciv-old/client/gui-xaw/gotodlg.c freeciv/client/gui-xaw/gotodlg.c
--- freeciv-old/client/gui-xaw/gotodlg.c        Wed Jul 21 07:54:58 1999
+++ freeciv/client/gui-xaw/gotodlg.c    Sat Jul 24 13:01:07 1999
@@ -63,6 +63,8 @@
                              XtPointer call_data);
 void goto_list_callback(Widget w, XtPointer client_data, XtPointer call_data);

+static void cleanup_goto_list();
+
 static char *dummy_city_list[]={ 
   "                                ",
   "                                ",
@@ -76,8 +79,8 @@
   0
 };
 
-static int ncities_total;
-static char **city_name_ptrs;
+static int ncities_total = 0;
+static char **city_name_ptrs = NULL;
 static int original_x, original_y;
 
 void popup_goto_dialog_action(Widget w, XEvent *event, String *argv, Cardinal
*argc)
@@ -199,7 +202,9 @@
   Boolean all_cities;
 
   XtVaGetValues(goto_all_toggle, XtNstate, &all_cities, NULL);
-  
+
+  cleanup_goto_list();
+
   if(all_cities)
     for(i=0, ncities_total=0; i<game.nplayers; i++)
       ncities_total+=city_list_size(&game.players[i].cities);
@@ -231,13 +236,9 @@
 **************************************************************************/
 static void popdown_goto_dialog(void)
 {
-  int i;
-  
-  for(i=0; i<ncities_total; i++)
-    free(*(city_name_ptrs+i));
-  
+  cleanup_goto_list();
+
   XtDestroyWidget(goto_dialog_shell);
-  free(city_name_ptrs);
   XtSetSensitive(main_form, TRUE);
 }
 
@@ -321,4 +322,25 @@
 {
   center_tile_mapcanvas(original_x, original_y);
   popdown_goto_dialog();
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void cleanup_goto_list()
+{
+  int i;
+
+  XawListChange(goto_list, dummy_city_list, 0, 0, FALSE);
+
+  if(city_name_ptrs)
+    {
+      for(i=0; i<ncities_total; i++)
+       {
+         free(*(city_name_ptrs+i));
+       }
+      free(city_name_ptrs);
+    }
+  ncities_total = 0;
+  city_name_ptrs = NULL;
 }



[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] xaw client Airlift/Goto dialog memory leak (PR#74), jjm <=