Skip to content

Commit

Permalink
Merge pull request #35 from hfiref0x/staging
Browse files Browse the repository at this point in the history
ABRT command race condition fix
v2.3.1
  • Loading branch information
hfiref0x authored Jun 30, 2024
2 parents 188e63b + 6e8c1ac commit ad83856
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Source/ftpserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,25 @@ void worker_thread_cleanup(PFTPCONTEXT context)
void *retv = NULL;

if ( context->WorkerThreadValid == 0 ) {

/*
* trying to stop gracefully
*/
context->WorkerThreadAbort = 1;
sleep(2);
sleep(1);

if ( context->DataSocket != INVALID_SOCKET ) {
close(context->DataSocket);
context->DataSocket = INVALID_SOCKET;
}

if ( context->hFile != -1 ) {
close(context->hFile);
context->hFile = -1;
}

context->DataIPv4 = 0;
context->DataPort = 0;
sleep(1);

if ( context->WorkerThreadValid == -1 )
return;

err = pthread_join(context->WorkerThreadId, &retv);
if ( err != 0)
Expand All @@ -246,19 +259,6 @@ void worker_thread_cleanup(PFTPCONTEXT context)

context->WorkerThreadValid = -1;
}

if ( context->DataSocket != INVALID_SOCKET ) {
close(context->DataSocket);
context->DataSocket = INVALID_SOCKET;
}

if ( context->hFile != -1 ) {
close(context->hFile);
context->hFile = -1;
}

context->DataIPv4 = 0;
context->DataPort = 0;
}

void worker_thread_start(PFTPCONTEXT context, PSTARTROUTINE fn)
Expand Down

0 comments on commit ad83856

Please sign in to comment.