From 191f45194b134c9ab635ab10b69727513daa2be3 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 3 Feb 2024 00:53:06 -0800 Subject: [PATCH] Clear g_dc each frame I was running into a memcpy of overlapping memory regions in R_RenderMaskedSegRange. - This is because of the reallocation of lightlists, which uses Z_Frame_Alloc. - The memory pool that Z_Frame_Alloc draws from is cleared each frame. - g_dc was not cleared though, so when the lightlists were reallocated, it'd try to copy from invalidated pointers. - Access to invalid pointers within the memory pool does not cause a segfault directly (because the memory pool is allocated once). However, a memcpy involving such an invalid pointer leads to overlap, which may cause memory corruption. --- src/d_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/d_main.c b/src/d_main.c index bc42372c8..4c9826ee9 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -836,6 +836,7 @@ void D_SRB2Loop(void) precise_t capbudget; precise_t enterprecise = I_GetPreciseTime(); + memset(&g_dc, 0, sizeof(g_dc)); Z_Frame_Reset(); // Casting the return value of a function is bad practice (apparently)