Read co->client only when co is locked
[pazpar2-moved-to-github.git] / src / connection.c
index e4c05f1..4ca648e 100644 (file)
@@ -239,10 +239,11 @@ void connection_continue(struct connection *co)
 static void connection_handler(IOCHAN iochan, int event)
 {
     struct connection *co = iochan_getdata(iochan);
-    struct client *cl = co->client;
+    struct client *cl;
     struct host *host = co->host;
 
     yaz_mutex_enter(host->mutex);
+    cl = co->client;
     if (!cl) 
     {
         /* no client associated with it.. We are probably getting
@@ -258,8 +259,8 @@ static void connection_handler(IOCHAN iochan, int event)
         {
             yaz_log(YLOG_WARN,  "connect timeout %s", client_get_url(cl));
 
-            connection_destroy(co);
             client_set_state(cl, Client_Error);
+            connection_destroy(co);
         }
         else if (client_get_state(co->client) == Client_Idle)
         {