Mesa (master): mesa: don' t allocate memory in _mesa_unpack_depth_span if we don't need it

Marek Olšák mareko at kemper.freedesktop.org
Fri Jun 24 21:14:54 UTC 2011


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

Author: Marek Olšák <maraeo at gmail.com>
Date:   Tue Jun 21 05:08:28 2011 +0200

mesa: don't allocate memory in _mesa_unpack_depth_span if we don't need it

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/main/pack.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 7d541dc..a232a51 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -4683,7 +4683,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
                          GLenum srcType, const GLvoid *source,
                          const struct gl_pixelstore_attrib *srcPacking )
 {
-   GLfloat *depthTemp, *depthValues;
+   GLfloat *depthTemp = NULL, *depthValues;
    GLboolean needClamp = GL_FALSE;
 
    /* Look for special cases first.
@@ -4729,16 +4729,16 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
 
    /* general case path follows */
 
-   depthTemp = (GLfloat *) malloc(n * sizeof(GLfloat));
-   if (!depthTemp) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
-      return;
-   }
-
    if (dstType == GL_FLOAT) {
       depthValues = (GLfloat *) dest;
    }
    else {
+      depthTemp = (GLfloat *) malloc(n * sizeof(GLfloat));
+      if (!depthTemp) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+         return;
+      }
+
       depthValues = depthTemp;
    }
 




More information about the mesa-commit mailing list