Mesa (master): mesa: fix mem leak of glPixelMap data in display list

Brian Paul brianp at kemper.freedesktop.org
Fri Nov 29 13:44:51 UTC 2013


Module: Mesa
Branch: master
Commit: 1fb106527faa195197fa52e28e1b941c97e520c2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1fb106527faa195197fa52e28e1b941c97e520c2

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Nov 29 06:40:35 2013 -0700

mesa: fix mem leak of glPixelMap data in display list

And simplify save_PixelMapfv() by using the memdup() function.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/mesa/main/dlist.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c
index 83c56a7..7f4ad17 100644
--- a/src/mesa/main/dlist.c
+++ b/src/mesa/main/dlist.c
@@ -719,6 +719,9 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist)
             free(n[4].data);
             n += InstSize[n[0].opcode];
             break;
+         case OPCODE_PIXEL_MAP:
+            free(n[3].data);
+            break;
 
          case OPCODE_CONTINUE:
             n = (Node *) n[1].next;
@@ -897,6 +900,18 @@ unpack_image(struct gl_context *ctx, GLuint dimensions,
    return NULL;
 }
 
+
+/** Return copy of memory */
+static void *
+memdup(const void *src, GLsizei bytes)
+{
+   void *b = bytes >= 0 ? malloc(bytes) : NULL;
+   if (b)
+      memcpy(b, src, bytes);
+   return b;
+}
+
+
 /**
  * Allocate space for a display list instruction (opcode + payload space).
  * \param opcode  the instruction opcode (OPCODE_* value)
@@ -2781,8 +2796,7 @@ save_PixelMapfv(GLenum map, GLint mapsize, const GLfloat *values)
    if (n) {
       n[1].e = map;
       n[2].i = mapsize;
-      n[3].data = malloc(mapsize * sizeof(GLfloat));
-      memcpy(n[3].data, (void *) values, mapsize * sizeof(GLfloat));
+      n[3].data = memdup(values, mapsize * sizeof(GLfloat));
    }
    if (ctx->ExecuteFlag) {
       CALL_PixelMapfv(ctx->Exec, (map, mapsize, values));
@@ -5873,17 +5887,6 @@ save_Uniform4fARB(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
 }
 
 
-/** Return copy of memory */
-static void *
-memdup(const void *src, GLsizei bytes)
-{
-   void *b = bytes >= 0 ? malloc(bytes) : NULL;
-   if (b)
-      memcpy(b, src, bytes);
-   return b;
-}
-
-
 static void GLAPIENTRY
 save_Uniform1fvARB(GLint location, GLsizei count, const GLfloat *v)
 {




More information about the mesa-commit mailing list