[server,proxy] make peer_list access thread-safe and fix leaks

This commit is contained in:
Eric
2026-01-08 14:44:47 +08:00
parent fa8a31b4e5
commit aba17d0cf9

View File

@@ -585,7 +585,9 @@ static DWORD WINAPI pf_server_handle_peer(LPVOID arg)
proxyServer* server = (proxyServer*)client->ContextExtra;
WINPR_ASSERT(server);
ArrayList_Lock(server->peer_list);
size_t count = ArrayList_Count(server->peer_list);
ArrayList_Unlock(server->peer_list);
if (!pf_context_init_server_context(client))
goto out_free_peer;
@@ -763,12 +765,19 @@ static BOOL pf_server_start_peer(freerdp_peer* client)
hThread = CreateThread(NULL, 0, pf_server_handle_peer, args, CREATE_SUSPENDED, NULL);
if (!hThread)
{
free(args);
return FALSE;
}
args->thread = hThread;
if (!ArrayList_Append(server->peer_list, hThread))
ArrayList_Lock(server->peer_list);
const BOOL appended = ArrayList_Append(server->peer_list, hThread);
ArrayList_Unlock(server->peer_list);
if (!appended)
{
(void)CloseHandle(hThread);
free(args);
return FALSE;
}