Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2005:
[Freeciv-Dev] (PR#12022) duplicate pointers to playermap city causes mem
Home

[Freeciv-Dev] (PR#12022) duplicate pointers to playermap city causes mem

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: badamson@xxxxxxxxxxx, bh@xxxxxxxxxxxxxxxxxxx, xbertje@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#12022) duplicate pointers to playermap city causes memory corruption and erronous free
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 28 Jan 2005 23:44:16 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Reading over the maphand.c portions of the genlist patch I find this
little gem.  I also added a comment to the struct to make sure nobody
breaks this behavior by changing it.  The patch is untested.

-jason

? genlist.diff
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.155
diff -u -r1.155 maphand.c
--- server/maphand.c    22 Jan 2005 19:45:44 -0000      1.155
+++ server/maphand.c    29 Jan 2005 07:43:30 -0000
@@ -1196,7 +1196,7 @@
        if (!dest_tile->city) {
          dest_tile->city = fc_malloc(sizeof(struct dumb_city));
        }
-       dest_tile->city = from_tile->city;
+       *dest_tile->city = *from_tile->city;
        send_city_info_at_tile(pdest, pdest->connections, NULL, ptile);
       }
 
Index: server/maphand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.h,v
retrieving revision 1.51
diff -u -r1.51 maphand.h
--- server/maphand.h    7 Dec 2004 18:01:12 -0000       1.51
+++ server/maphand.h    29 Jan 2005 07:43:31 -0000
@@ -26,6 +26,8 @@
 struct conn_list;
 
 struct dumb_city{
+  /* Values in this struct are copied using a memcpy, so don't put any
+   * pointers in here. */
   int id;
   bool has_walls;
   bool occupied;

[Prev in Thread] Current Thread [Next in Thread]