From 3d6c756ab769870b88fe8266a172446f913d50be Mon Sep 17 00:00:00 2001 From: Colton Pawielski Date: Fri, 14 May 2021 08:57:10 -0400 Subject: [PATCH] Fix memory leaks in samples Add free to end of LoadGLTextures() to release image1 after use. --- samples/lerabot01/main.c | 2 ++ samples/lights/main.c | 2 ++ samples/mipmap/main.c | 2 ++ samples/nehe06/main.c | 2 ++ samples/nehe06_4444twid/main.c | 2 ++ samples/nehe06_vq/main.c | 2 ++ samples/paletted/main.c | 2 ++ 7 files changed, 14 insertions(+) diff --git a/samples/lerabot01/main.c b/samples/lerabot01/main.c index dfcb696..6d63f2c 100644 --- a/samples/lerabot01/main.c +++ b/samples/lerabot01/main.c @@ -134,6 +134,8 @@ void LoadGLTextures() { // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); + + free(image1); }; /* A general OpenGL initialization function. Sets all of the initial parameters. */ diff --git a/samples/lights/main.c b/samples/lights/main.c index 15088d7..23dd6ec 100644 --- a/samples/lights/main.c +++ b/samples/lights/main.c @@ -141,6 +141,8 @@ void LoadGLTextures() { glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); glGenerateMipmapEXT(GL_TEXTURE_2D); + + free(image1); }; diff --git a/samples/mipmap/main.c b/samples/mipmap/main.c index 0ab8447..43f5197 100644 --- a/samples/mipmap/main.c +++ b/samples/mipmap/main.c @@ -137,6 +137,8 @@ void LoadGLTextures() { glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); glGenerateMipmapEXT(GL_TEXTURE_2D); + + free(image1); }; /* A general OpenGL initialization function. Sets all of the initial parameters. */ diff --git a/samples/nehe06/main.c b/samples/nehe06/main.c index c712ba3..475f58e 100644 --- a/samples/nehe06/main.c +++ b/samples/nehe06/main.c @@ -140,6 +140,8 @@ void LoadGLTextures() { glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); glGenerateMipmapEXT(GL_TEXTURE_2D); + + free(image1); }; /* A general OpenGL initialization function. Sets all of the initial parameters. */ diff --git a/samples/nehe06_4444twid/main.c b/samples/nehe06_4444twid/main.c index 94125ae..d5f05b7 100644 --- a/samples/nehe06_4444twid/main.c +++ b/samples/nehe06_4444twid/main.c @@ -156,6 +156,8 @@ void LoadGLTextures() { GL_TEXTURE_2D, 0, image1->internal_format, image1->sizeX, image1->sizeY, 0, image1->format, image1->type, image1->data ); + + free(image1); }; /* A general OpenGL initialization function. Sets all of the initial parameters. */ diff --git a/samples/nehe06_vq/main.c b/samples/nehe06_vq/main.c index c4501e2..cf1e416 100644 --- a/samples/nehe06_vq/main.c +++ b/samples/nehe06_vq/main.c @@ -162,6 +162,8 @@ void LoadGLTextures() { GL_TEXTURE_2D, 0, image1->internalFormat, image1->sizeX, image1->sizeY, 0, image1->dataSize, image1->data ); + + free(image1); }; /* A general OpenGL initialization function. Sets all of the initial parameters. */ diff --git a/samples/paletted/main.c b/samples/paletted/main.c index 69826da..1e13df3 100644 --- a/samples/paletted/main.c +++ b/samples/paletted/main.c @@ -125,6 +125,8 @@ void LoadGLTextures() { // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, image1->width, image1->height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE_TWID_KOS, image1->data); glGenerateMipmapEXT(GL_TEXTURE_2D); + + free(image1); } /* A general OpenGL initialization function. Sets all of the initial parameters. */