From e3c42b3ba2e764042417d97317856d814742ae02 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 29 Mar 2024 23:48:33 +0100 Subject: [PATCH] add more safety --- src/hardware/hw_cache.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 35472b85..5d03c416 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -481,7 +481,7 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) { GLPatch_t* const pat = patch; (void)patchnum; //unused - + // The patch must be valid, obviously if (!pat) return; @@ -498,19 +498,23 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) if (!pat->mipmap) break; - // No colormap mipmap either. + // No colormap mipmaps either. if (!pat->mipmap->nextcolormap) break; // Set the first colormap to the one that comes after it. next = pat->mipmap->nextcolormap; + if (!next) + break; + pat->mipmap->nextcolormap = next->nextcolormap; // Free image data from memory. if (next->grInfo.data) Z_Free(next->grInfo.data); + next->grInfo.data = NULL; - // Free the old colormap from memory. + // Free the old colormap mipmap from memory. free(next); } }