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

Brian Paul brianp at vmware.com
Fri Jun 10 14:20:45 UTC 2016


On 06/10/2016 05:30 AM, Amarnath Valluri wrote:
> 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 */
>

I'll push this patch with a few minor changes:
1. fix indentation to match surrounding code.
2. remove if-test around the second free().  free(NULL) is a no-op.
3. remove unneeded comments.
4. List the bug URL in the check-in comment.

Sound OK?

Thanks for the patch!

-Brian



More information about the mesa-dev mailing list