From aca48d45b32f5ec09c960a999f5e5abb1273731f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 17:29:27 +0100 Subject: [PATCH 1/2] fix potential crash with perfstats https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2576 --- src/m_perfstats.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 3c5526678..14980b162 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -452,7 +452,7 @@ static int PS_DrawPerfRows(int x, int y, int color, perfstatrow_t *rows) return draw_y; } -static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boolean frame_metric, boolean set_user) +static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boolean frame_metric) { int index = frame_metric ? ps_frame_index : ps_tick_index; @@ -460,7 +460,7 @@ static void PS_UpdateMetricHistory(ps_metric_t *metric, boolean time_metric, boo { // allocate history table int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); - void** memory_user = set_user ? &metric->history : NULL; + void** memory_user = &metric->history; metric->history = Z_Calloc(value_size * cv_ps_samplesize.value, PU_PERFSTATS, memory_user); @@ -490,7 +490,7 @@ static void PS_UpdateRowHistories(perfstatrow_t *rows, boolean frame_metric) for (row = rows; row->lores_label; row++) { if (PS_IsRowValid(row)) - PS_UpdateMetricHistory(row->metric, !!(row->flags & PS_TIME), frame_metric, true); + PS_UpdateMetricHistory(row->metric, !!(row->flags & PS_TIME), frame_metric); } } @@ -670,17 +670,17 @@ void PS_UpdateTickStats(void) if (cv_perfstats.value == 3) { for (i = 0; i < thinkframe_hooks_length; i++) - PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false); } else if (cv_perfstats.value == 4) { for (i = 0; i < prethinkframe_hooks_length; i++) - PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false, false); + PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false); } else if (cv_perfstats.value == 5) { for (i = 0; i < postthinkframe_hooks_length; i++) - PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false, false); + PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false); } } if (cv_perfstats.value) From 182500c2d2880fb6e2a7263702b5b2ec3bd11177 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Dec 2024 17:34:13 +0100 Subject: [PATCH 2/2] fix potential Fix segfault when aborting HTTP download --- src/d_netfil.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/d_netfil.c b/src/d_netfil.c index 2559cbcf1..fd0bf879c 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -111,6 +111,7 @@ static fileused_t transferFiles[UINT8_MAX + 1]; // Receiver structure INT32 fileneedednum; // Number of files needed to join the server fileneeded_t fileneeded[MAX_WADFILES]; // List of needed files +static I_mutex downloadmutex; char downloaddir[512] = "DOWNLOAD"; #ifdef CLIENT_LOADINGSCREEN @@ -1327,6 +1328,7 @@ void CURLPrepareFile(const char* url, int dfilenum) curl_starttime = time(NULL); curl_running = true; + #ifdef HAVE_THREADS I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL); #endif @@ -1336,10 +1338,15 @@ void CURLPrepareFile(const char* url, int dfilenum) void CURLAbortFile(void) { curl_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 */ @@ -1432,6 +1439,7 @@ void CURLGetFile(void) multi_handle = NULL; } curl_running = false; + I_unlock_mutex(downloadmutex); } HTTP_login *