From 8bb845b0376ccfaa1d8c8157dbb471abd15e283c Mon Sep 17 00:00:00 2001 From: Yamagi Date: Mon, 1 Nov 2021 18:42:40 +0100 Subject: [PATCH] Fix potential memory leak in R_Upload8() in GL1. This is a corner case, next to unlikely that anyone would have ever hit it. That's why my tests with asan didn't find the leak. The if case are paletted textures which must be enabled by setting `gl1_palettedtexture` to 1 and requires an GPU with support for `GL_EXT_paletted_texture`. Nvidia dropped support for that in 2005. Additionally a sky texture must be uploaded. --- src/client/refresh/gl1/gl1_image.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index 5573a955..299a0a0f 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -786,7 +786,6 @@ qboolean R_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) { int s = width * height; - unsigned *trans = malloc(s * sizeof(unsigned)); if (gl_config.palettedtexture && is_sky) { @@ -801,6 +800,8 @@ R_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) } else { + unsigned *trans = malloc(s * sizeof(unsigned)); + for (int i = 0; i < s; i++) { int p = data[i];