From 08a2d61d6d0c70f08093d6fc5fde2e430524574e Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 12 Jan 2023 10:40:41 +0100 Subject: [PATCH] [proxy] fix possible NULL crash on shutdown --- server/proxy/pf_server.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/proxy/pf_server.c b/server/proxy/pf_server.c index 29e5be84a..d5d7dfb29 100644 --- a/server/proxy/pf_server.c +++ b/server/proxy/pf_server.c @@ -1035,16 +1035,19 @@ void pf_server_free(proxyServer* server) pf_server_stop(server); - while (ArrayList_Count(server->peer_list) > 0) + if (server->peer_list) { - /* pf_server_stop triggers the threads to shut down. - * loop here until all of them stopped. - * - * This must be done before ArrayList_Free otherwise the thread removal - * in pf_server_handle_peer will deadlock due to both threads trying to - * lock the list. - */ - Sleep(100); + while (ArrayList_Count(server->peer_list) > 0) + { + /* pf_server_stop triggers the threads to shut down. + * loop here until all of them stopped. + * + * This must be done before ArrayList_Free otherwise the thread removal + * in pf_server_handle_peer will deadlock due to both threads trying to + * lock the list. + */ + Sleep(100); + } } ArrayList_Free(server->peer_list); freerdp_listener_free(server->listener);