From 35c86aac4ac1f10f110f0a16b90eaaea08b925bd Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Tue, 7 Jan 2014 12:27:12 +0000 Subject: [PATCH] Resolve more _beginthread() race conditions by incrementing the thread_count *before* calling _beginthread(). The active_clients is exactly perfect here either (since it's incrementing in the ctrl_thread), todo later, but shouldn't cause a crash like the above issue. --- src/sbbs3/ftpsrvr.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sbbs3/ftpsrvr.c b/src/sbbs3/ftpsrvr.c index 559d304c0d..55dbbfc6cd 100644 --- a/src/sbbs3/ftpsrvr.c +++ b/src/sbbs3/ftpsrvr.c @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2012 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2014 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -208,10 +208,9 @@ static void client_off(SOCKET sock) static int32_t thread_up(BOOL setuid) { - int32_t count = protected_uint32_adjust(&thread_count,1); if(startup!=NULL && startup->thread_up!=NULL) startup->thread_up(startup->cbdata,TRUE, setuid); - return count; + return thread_count.value; } static int32_t thread_down(void) @@ -1918,6 +1917,7 @@ static void filexfer(SOCKADDR_IN* addr, SOCKET ctrl_sock, SOCKET pasv_sock, SOCK xfer->dir=dir; xfer->desc=desc; SAFECOPY(xfer->filename,filename); + protected_uint32_adjust(&thread_count,1); if(receiving) result=_beginthread(receive_thread,0,(void*)xfer); else @@ -4636,6 +4636,7 @@ void DLLCALL ftp_server(void* arg) do { + protected_uint32_adjust(&thread_count,1); thread_up(FALSE /* setuid */); status("Initializing"); @@ -4893,6 +4894,7 @@ void DLLCALL ftp_server(void* arg) ftp->socket=client_socket; ftp->client_addr=client_addr; + protected_uint32_adjust(&thread_count,1); _beginthread(ctrl_thread, 0, ftp); served++; } -- GitLab