[PATCH 2/2] Fix channel use after freeing in main loop

From: Vasily Kolobkov <no email>
Date: Sun, 14 Feb 2016 13:07:17 +0200

---
 ii.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/ii.c b/ii.c
index 632ee4b..745e29a 100644
--- a/ii.c
+++ b/ii.c
_AT_@ -414,15 +414,15 @@ static void handle_server_output() {
 		perror("ii: remote host closed connection");
 		exit(EXIT_FAILURE);
 	}
 	proc_server_cmd(buf);
 }
 
 static void run() {
-	Channel *c;
+	Channel *c, *n;
 	int r, maxfd;
 	fd_set rd;
 	struct timeval tv;
 	char ping_msg[512];
 
 	snprintf(ping_msg, sizeof(ping_msg), "PING %s\r\n", host);
 	for(;;) {
_AT_@ -451,17 +451,19 @@ static void run() {
 			write(irc, ping_msg, strlen(ping_msg));
 			continue;
 		}
 		if(FD_ISSET(irc, &rd)) {
 			handle_server_output();
 			last_response = time(NULL);
 		}
-		for(c = channels; c; c = c->next)
+		for(c = channels; c; c = n) {
+			n = c->next;
 			if(FD_ISSET(c->fd, &rd))
 				handle_channels_input(c);
+		}
 	}
 }
 
 int main(int argc, char *argv[]) {
 	int i;
 	unsigned short port = SERVER_PORT;
 	struct passwd *spw = getpwuid(getuid());
-- 
2.7.0
--YA2xvTDiwmundsEt--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sun Feb 14 2016 - 13:48:13 CET