dtls connection setup: fix memory corruption, proper watcher setup

ev_init and ev_io_set must never be called on active watchers - we
need to cleanup previous connection state before setting a new one.

ev_init clears the "active" flag, but doesn't remove the watcher from
libev internal linked lists (and doesn't clear the "next" pointer for
it).  This can for example lead to (unexpected) cyclic lists in libev,
and libev can loop forever trying to deal with them.
This commit is contained in:
Stefan Bühler
2021-02-10 13:23:42 +01:00
parent 9f08770c08
commit 4cea55c6d6

View File

@@ -431,7 +431,7 @@ static int setup_dtls_connection(struct worker_st *ws, struct dtls_st * dtls)
}
dtls->dtls_session = session;
ev_init(&dtls->io, dtls_watcher_cb);
ev_io_stop(worker_loop, &dtls->io);
ev_io_set(&dtls->io, dtls->dtls_tptr.fd, EV_READ);
ev_io_start(worker_loop, &dtls->io);
ev_invoke(worker_loop, &dtls->io, EV_READ);