From c04dd70a433edb19055d7d1e8b50fcbb954a9465 Mon Sep 17 00:00:00 2001
From: Hanicef <gustaf@hanicef.me>
Date: Fri, 16 Feb 2024 18:38:40 +0100
Subject: [PATCH] Avoid double initialization of CURL

---
 src/netcode/d_netfil.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/netcode/d_netfil.c b/src/netcode/d_netfil.c
index ee1f7a9b26..da3a8727b8 100644
--- a/src/netcode/d_netfil.c
+++ b/src/netcode/d_netfil.c
@@ -1609,11 +1609,13 @@ boolean CURLPrepareFile(const char* url, int dfilenum)
 		I_Error("Attempted to download files in -nodownload mode");
 #endif
 
-	curl_global_init(CURL_GLOBAL_ALL);
+	if (!multi_handle)
+	{
+		curl_global_init(CURL_GLOBAL_ALL);
+		multi_handle = curl_multi_init();
+	}
 
 	http_handle = curl_easy_init();
-	multi_handle = curl_multi_init();
-
 	if (http_handle && multi_handle)
 	{
 		I_mkdir(downloaddir, 0755);
@@ -1782,10 +1784,11 @@ void CURLGetFile(void)
 		}
 	}
 
-	if (!filedownload.remaining)
+	if (!filedownload.remaining || !filedownload.http_running)
 	{
 		curl_multi_cleanup(multi_handle);
 		curl_global_cleanup();
+		multi_handle = NULL;
 	}
 	filedownload.http_running = false;
 }
-- 
GitLab