From 93d48ca97e59fc045b566f320d5c5bed5e0771fb Mon Sep 17 00:00:00 2001 From: Hanicef Date: Mon, 30 Dec 2024 17:12:56 +0100 Subject: [PATCH] Fix segfault when aborting HTTP download --- src/netcode/d_netfil.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/netcode/d_netfil.c b/src/netcode/d_netfil.c index da3a8727b..313905f43 100644 --- a/src/netcode/d_netfil.c +++ b/src/netcode/d_netfil.c @@ -95,6 +95,7 @@ static filetran_t transfer[MAXNETNODES]; INT32 fileneedednum; // Number of files needed to join the server fileneeded_t *fileneeded; // List of needed files static tic_t lasttimeackpacketsent = 0; +static I_mutex downloadmutex; char downloaddir[512] = "DOWNLOAD"; // For resuming failed downloads @@ -1687,10 +1688,15 @@ boolean CURLPrepareFile(const char* url, int dfilenum) void CURLAbortFile(void) { filedownload.http_running = false; + + // lock and unlock to wait for the download thread to exit + I_lock_mutex(&downloadmutex); + I_unlock_mutex(downloadmutex); } void CURLGetFile(void) { + I_lock_mutex(&downloadmutex); CURLMcode mc; /* return code used by curl_multi_wait() */ CURLcode easyres; /* Return from easy interface */ CURLMsg *m; /* for picking up messages with the transfer status */ @@ -1791,6 +1797,7 @@ void CURLGetFile(void) multi_handle = NULL; } filedownload.http_running = false; + I_unlock_mutex(downloadmutex); } HTTP_login *