Corrected a bug that causes segfaults if UDP packets are received when no client...
[umurmur.git] / src / client.c
index 94da524243ee4fbd69afc96ae48c276e09607c06..74633613b744401636c10eee2c7a3b535d5f5bac 100644 (file)
@@ -94,8 +94,11 @@ void Client_janitor()
                if (c->availableBandwidth > bwTop)
                        c->availableBandwidth = bwTop;
                
-               if (Timer_isElapsed(&c->lastActivity, 1000000LL * INACTICITY_TIMEOUT))
-                       Client_close(c);
+               if (Timer_isElapsed(&c->lastActivity, 1000000LL * INACTICITY_TIMEOUT)) {
+                       /* No activity from client - assume it is lost and close. */
+                       Log_info("Session ID %d timeout - closing", c->sessionId);
+                       Client_free(c);
+               }
        }
 }
 
@@ -374,8 +377,11 @@ int Client_send_message(client_t *client, message_t *msg)
 client_t *Client_iterate(client_t **client_itr)
 {
        client_t *c = *client_itr;
+
+       if (list_empty(&clients))
+               return NULL;
        
-       if (c == NULL && !list_empty(&clients)) {
+       if (c == NULL) {
                c = list_get_entry(list_get_first(&clients), client_t, node);
        } else {
                if (list_get_next(&c->node) == &clients)
@@ -524,10 +530,14 @@ static void Client_voiceMsg_tunnel(client_t *client, message_t *msg)
        Pds_add_numval(pds, msg->sessionId);
        Pds_add_numval(pds, msg->payload.speex.seq);
        Pds_append_data_nosize(pds, msg->payload.speex.data, msg->payload.speex.size);
+       
+       Msg_free(msg);
+       
        if (!pds->bOk)
                Log_warn("Large Speex message from TCP"); /* XXX - pds resize? */
        pds->maxsize = pds->offset;
        Client_voiceMsg(client, pds);
+       
        Pds_free(pds);
 }