Fix double free in silcd.
authorSkywing <skywing@valhallalegends.com>
Fri, 20 Jun 2008 21:19:32 +0000 (16:19 -0500)
committerKp <kp@valhallalegends.com>
Mon, 1 Sep 2008 20:15:15 +0000 (15:15 -0500)
apps/silcd/command.c
apps/silcd/server_util.c

index 8040467..d8d105c 100644 (file)
@@ -1472,12 +1472,19 @@ SILC_SERVER_CMD_FUNC(kill)
 
     /* Do normal signoff for the destination client */
     sock = remote_client->connection;
+
+    if (sock)
+      silc_packet_stream_ref(sock);
+
     silc_server_remove_from_channels(server, NULL, remote_client,
                                     TRUE, (char *)"Killed", TRUE, TRUE);
     silc_server_free_sock_user_data(server, sock, comment ? comment :
                                    (unsigned char *)"Killed");
-    if (sock)
+    if (sock) {
+      silc_packet_set_context(sock, NULL);
       silc_server_close_connection(server, sock);
+      silc_packet_stream_unref(sock);
+    }
   } else {
     /* Router operator killing */
 
index d2fd526..74ce18b 100644 (file)
@@ -1547,8 +1547,17 @@ void silc_server_kill_client(SilcServer server,
   if (remote_client->connection) {
     /* Remove locally conneted client */
     SilcPacketStream sock = remote_client->connection;
+
+    if (sock)
+      silc_packet_stream_ref(sock);
+
     silc_server_free_sock_user_data(server, sock, NULL);
-    silc_server_close_connection(server, sock);
+
+    if (sock) {
+      silc_packet_set_context(sock, NULL);
+      silc_server_close_connection(server, sock);
+      silc_packet_stream_unref(sock);
+    }
   } else {
     /* Update statistics */
     server->stat.clients--;