# HG changeset patch # User Matt Johnston # Date 1443536351 -28800 # Node ID 57d09741d46d5c654564a99671a6b712f0913b53 # Parent a550e1e2e2a90e203b9a2e55c0c25e1bba92571d avoid invalidated iterator when connection fails diff -r a550e1e2e2a9 -r 57d09741d46d netio.c --- a/netio.c Tue Sep 29 21:53:27 2015 +0800 +++ b/netio.c Tue Sep 29 22:19:11 2015 +0800 @@ -174,28 +174,26 @@ void set_connect_fds(fd_set *writefd) { m_list_elem *iter; - TRACE(("enter handle_connect_fds")) - for (iter = ses.conn_pending.first; iter; iter = iter->next) { + TRACE(("enter set_connect_fds")) + iter = ses.conn_pending.first; + while (iter) { + m_list_elem *next_iter = iter->next; struct dropbear_progress_connection *c = iter->item; /* Set one going */ - while (c->res_iter && c->sock < 0) - { + while (c->res_iter && c->sock < 0) { connect_try_next(c); } if (c->sock >= 0) { FD_SET(c->sock, writefd); } else { - m_list_elem *remove_iter; /* Final failure */ if (!c->errstring) { c->errstring = m_strdup("unexpected failure"); } c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring); - /* Safely remove without invalidating iter */ - remove_iter = iter; - iter = iter->prev; - remove_connect(c, remove_iter); + remove_connect(c, iter); } + iter = next_iter; } }