[Mesa-dev] [RFC PATCH 1/4] mesa/pack: check malloc return value

Giuseppe Bilotta giuseppe.bilotta at gmail.com
Sat Apr 22 07:52:11 UTC 2017


Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
---
 src/mesa/main/pack.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 760c46afe7..16bc95311b 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -1621,6 +1621,11 @@ _mesa_unpack_color_index_to_rgba_ubyte(struct gl_context *ctx, GLuint dims,
 
    count = srcWidth * srcHeight * srcDepth;
    dst = malloc(count * 4 * sizeof(GLubyte));
+   if (!dst) {
+      free(rgba);
+      _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+      return NULL;
+   }
    for (i = 0; i < count; i++) {
       CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 0], rgba[i * 4 + 0]);
       CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 1], rgba[i * 4 + 1]);
-- 
2.13.0.rc0.207.gb442654931



More information about the mesa-dev mailing list