Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] Re: (PR#8585) client crash in packets code
Home

[Freeciv-Dev] Re: (PR#8585) client crash in packets code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8585) client crash in packets code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 25 Apr 2004 16:06:52 -0700
Reply-to: rt@xxxxxxxxxxx

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

Raimar Falke wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8585 >
> 
> On Sun, Apr 25, 2004 at 12:02:14AM -0700, Jason Short wrote:
> 
>><URL: http://rt.freeciv.org/Ticket/Display.html?id=8585 >
>>
>>I started a game through the conndlg, then (after nation selection) 
>>immediately disconnected.  I started another, and (when I pressed the 
>>"start" button) the client immediately crashed.
>>
>>This seems to be reproducable.  But if I connect to a network game in 
>>between I can then go back and launch another game.
> 
> 
> The reason is that you try to send using a closed connection. After
> connection_common_close() you have to call connection_common_init() to
> use the connection again.
> 
> So try to find the error in some upper layers.

I believe this is the correct way to fix the problem.

We could create a new function is_server_running_and_attached(), but I 
think almost all callers would then just have to use this function.

jason

Index: client/connectdlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/connectdlg_common.c,v
retrieving revision 1.10
diff -u -r1.10 connectdlg_common.c
--- client/connectdlg_common.c  25 Apr 2004 19:03:40 -0000      1.10
+++ client/connectdlg_common.c  25 Apr 2004 23:03:21 -0000
@@ -108,8 +108,12 @@
 /************************************************************************** 
 Tests if the client has started the server.
 **************************************************************************/ 
-bool is_server_running()
-{ 
+bool is_server_running(void)
+{
+  if (!aconnection.used) {
+    return FALSE;
+  }
+
 #ifdef WIN32_NATIVE
   return (server_process != INVALID_HANDLE_VALUE);
 #else    
@@ -120,19 +124,21 @@
 /************************************************************************** 
 Kills the server if the client has started it (FIXME: atexit handler?)
 **************************************************************************/ 
-void client_kill_server()
+void client_kill_server(void)
 {
-  if (is_server_running()) {
 #ifdef WIN32_NATIVE
+  if (server_process != INVALID_HANDLE_VALUE) {
     TerminateProcess(server_process, 0);
     CloseHandle(server_process);
-    server_process = INVALID_HANDLE_VALUE;             
+    server_process = INVALID_HANDLE_VALUE;
+  }
 #else
+  if (server_pid > 0) {
     kill(server_pid, SIGTERM);
     waitpid(server_pid, NULL, WUNTRACED);
     server_pid = - 1;
-#endif    
   }
+#endif    
 }   
 
 /**************************************************************** 

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