Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] Re: (PR#8500) packet_single_want_hack_req isn't freed
Home

[Freeciv-Dev] Re: (PR#8500) packet_single_want_hack_req isn't freed

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#8500) packet_single_want_hack_req isn't freed
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 Apr 2004 16:43:44 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8500 >

Raimar Falke wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8500 >
> 
> On Mon, Apr 12, 2004 at 02:44:51PM -0700, Jason Short wrote:
> 
>><URL: http://rt.freeciv.org/Ticket/Display.html?id=8500 >
>>
>>jdorje@xxxxxxxxxxxx wrote:
>>
>>
>>>However this isn't clean because the caller gives us packet directly. 
>>>It should be the caller who frees it.
>>
>>And a patch.
> 
> 
> And do the same thing to the client.

Easy enough, although this one isn't quite as helpful.

jason

Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.186
diff -u -r1.186 civclient.c
--- client/civclient.c  10 Apr 2004 03:47:48 -0000      1.186
+++ client/civclient.c  12 Apr 2004 23:43:04 -0000
@@ -284,8 +284,6 @@
     freelog(LOG_ERROR, "Received unknown packet (type %d) from server!",
            type);
   }
-
-  free(packet);
 }
 
 /**************************************************************************
Index: client/clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.95
diff -u -r1.95 clinet.c
--- client/clinet.c     3 Feb 2004 20:21:14 -0000       1.95
+++ client/clinet.c     12 Apr 2004 23:43:04 -0000
@@ -316,13 +316,14 @@
   if (read_from_connection(&aconnection, FALSE) >= 0) {
     enum packet_type type;
     bool result;
-    void *packet;
 
     while (TRUE) {
-      packet = get_packet_from_connection(&aconnection, &type, &result);
-      if (result) {
+      void *packet = get_packet_from_connection(&aconnection,
+                                               &type, &result);
+
+      if (result && packet) {
        handle_packet_input(packet, type);
-       packet = NULL;
+       free(packet);
       } else {
        break;
       }
@@ -354,16 +355,16 @@
     if (read_from_connection(&aconnection, TRUE) >= 0) {
       enum packet_type type;
       bool result;
-      void *packet;
 
       while (TRUE) {
-       packet = get_packet_from_connection(&aconnection, &type, &result);
-       if (!result) {
+       void *packet = get_packet_from_connection(&aconnection,
+                                                 &type, &result);
+       if (!result || !packet) {
          break;
        }
 
        handle_packet_input(packet, type);
-       packet = NULL;
+       free(packet);
 
        if (type == PACKET_PROCESSING_FINISHED) {
          freelog(LOG_DEBUG, "ifstrgp: expect=%d, seen=%d",

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