From a33d1e28e91c83dc505858aab3d249999b95e40d Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Fri, 20 Jun 2014 17:46:47 +0200 Subject: [PATCH] unix-manager: fix crash when client disconnect This patch fixes an issue in unix socket handling. It is possible that a socket did disconnect when analysing a command and because the data treatment is done in a loop on clients this was leading to a update of the list of clients during the loop. So we need in fact to use TAILQ_FOREACH_SAFE instead of TAILQ_FOREACH. Reported-by: Luigi Sandon Fix-suggested-by: Luigi Sandon --- src/unix-manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/unix-manager.c b/src/unix-manager.c index 5fc0054bc6..2d0a90641a 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -495,6 +495,7 @@ int UnixMain(UnixCommand * this) int ret; fd_set select_set; UnixClient *uclient; + UnixClient *tclient; /* Wait activity on the socket */ FD_ZERO(&select_set); @@ -526,7 +527,7 @@ int UnixMain(UnixCommand * this) return 1; } - TAILQ_FOREACH(uclient, &this->clients, next) { + TAILQ_FOREACH_SAFE(uclient, &this->clients, next, tclient) { if (FD_ISSET(uclient->fd, &select_set)) { UnixCommandRun(this, uclient); }