From 5e28e358ad5342f9092b3daef0e9645ad6930dbf Mon Sep 17 00:00:00 2001
From: Jaime Passos <lazymyuutsu@gmail.com>
Date: Fri, 15 May 2020 15:43:40 -0300
Subject: [PATCH] Fix memory leak

---
 src/r_textures.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/r_textures.c b/src/r_textures.c
index 8ff85de43e..7e3d8445d4 100644
--- a/src/r_textures.c
+++ b/src/r_textures.c
@@ -410,10 +410,18 @@ UINT8 *R_GenerateTexture(size_t texnum)
 		x2 = x1 + width;
 
 		if (x1 > texture->width || x2 < 0)
+		{
+			if (dealloc)
+				Z_Free(realpatch);
 			continue; // patch not located within texture's x bounds, ignore
+		}
 
 		if (patch->originy > texture->height || (patch->originy + height) < 0)
+		{
+			if (dealloc)
+				Z_Free(realpatch);
 			continue; // patch not located within texture's y bounds, ignore
+		}
 
 		// patch is actually inside the texture!
 		// now check if texture is partly off-screen and adjust accordingly
-- 
GitLab