[Mesa-dev] [PATCH] libutils/mipmap.c: Fixed possible memory leak

Amarnath Valluri amarnath.valluri at intel.com
Fri Jun 10 11:30:17 UTC 2016


In case of malloc() failure memory allocated for both 'srcImage' and 'dstImage'
is leaked.

Signed-off-by: Amarnath Valluri <amarnath.valluri at intel.com>
---
 src/libutil/mipmap.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/libutil/mipmap.c b/src/libutil/mipmap.c
index c475c96..1f718a6 100644
--- a/src/libutil/mipmap.c
+++ b/src/libutil/mipmap.c
@@ -4509,7 +4509,11 @@ static int gluBuild2DMipmapLevelsCore(GLenum target, GLint internalFormat,
 	     glPixelStorei(GL_UNPACK_SKIP_PIXELS, psm.unpack_skip_pixels);
 	     glPixelStorei(GL_UNPACK_ROW_LENGTH, psm.unpack_row_length);
 	     glPixelStorei(GL_UNPACK_SWAP_BYTES, psm.unpack_swap_bytes);
-	     return GLU_OUT_OF_MEMORY;
+       free(srcImage); /*if you get to here, a srcImage has always been malloc'ed*/
+       if (dstImage) { /* if it's non-rectangular and only 1 level */
+          free(dstImage);
+       }
+       return GLU_OUT_OF_MEMORY;
 	  }
 
 	  /* copy image from srcImage into newMipmapImage by rows */
-- 
2.5.0

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.



More information about the mesa-dev mailing list