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 <luigi.sandon@gmail.com>
Fix-suggested-by: Luigi Sandon <luigi.sandon@gmail.com>
pull/1001/head
Eric Leblond 11 years ago committed by Victor Julien
parent 6ebc20f6d8
commit a33d1e28e9

@ -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);
}

Loading…
Cancel
Save