Fix a crash when an outbound client is closed in response to reading a remote message.

When we read from some client A, we may end up forwarding a message to other
clients. If we forward to some client B and there is a write error, then
we close B and remove it from the client list. However, if before this happened
A->next == B, then the read loop will still be holding on to a pointer to B,
and we crash.

As it's unpredictable what clients could be closed at what point, the simplest
approach is to retain closed clients in the list until we are at a point where
we know there are no stray pointers on stack, and only then modify the list.
This also simplifies anything that has to loop over clients, as it doesn't need
to worry about the current client being freed under it.
This commit is contained in:
Oliver Jowett 2014-10-02 21:06:10 +01:00
parent bf111360bc
commit a2f49f2bb8
3 changed files with 30 additions and 28 deletions

View file

@ -490,6 +490,7 @@ void showCopyright(void) {
void backgroundTasks(void) {
if (Modes.net) {
modesReadFromClients();
modesNetCleanup();
}
// If Modes.aircrafts is not NULL, remove any stale aircraft