diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 02ae6556e..80161b4be 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -392,6 +392,9 @@ poll_thread(void *arg) slirp_log("SLiRP: polling stopped.\n"); thread_set_event(slirp->poll_state); + /* Destroy event here to avoid a crash. */ + slirp_log("SLiRP: thread ended\n"); + thread_destroy_event(slirp->poll_state); /* Free here instead of immediately freeing the global slirp on the main thread to avoid a race condition. */ slirp_cleanup(slirp->slirp); @@ -451,8 +454,6 @@ net_slirp_close(void) /* Wait for the thread to finish. */ slirp_log("SLiRP: waiting for thread to end...\n"); thread_wait_event(slirp->poll_state, -1); - slirp_log("SLiRP: thread ended\n"); - thread_destroy_event(slirp->poll_state); } /* Shutdown work is done by the thread on its local copy of slirp. */