[Mesa-dev] [PATCH] egl: return EGL_BAD_ALLOC if _eglConvertAttribsToInt fails

Marek Olšák maraeo at gmail.com
Tue May 26 14:59:58 PDT 2015


From: Marek Olšák <marek.olsak at amd.com>

This is a fix for the EGL 1.5 patch series.
---
 src/egl/main/eglapi.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 7afc091..3df4968 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -263,13 +263,14 @@ _eglConvertAttribsToInt(const EGLAttrib *attr_list)
       while (attr_list[size] != EGL_NONE)
          size += 2;
 
-      if (size) {
-         size += 1; /* add space for EGL_NONE */
-         int_attribs = malloc(size * sizeof(int_attribs[0]));
+      size += 1; /* add space for EGL_NONE */
 
-         for (i = 0; i < size; i++)
-            int_attribs[i] = attr_list[i];
-      }
+      int_attribs = malloc(size * sizeof(int_attribs[0]));
+      if (!int_attribs)
+         return NULL;
+
+      for (i = 0; i < size; i++)
+         int_attribs[i] = attr_list[i];
    }
    return int_attribs;
 }
@@ -332,6 +333,9 @@ eglGetPlatformDisplay(EGLenum platform, void *native_display,
    EGLDisplay display;
    EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
 
+   if (attrib_list && !int_attribs)
+      RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, NULL);
+
    display = eglGetPlatformDisplayEXT(platform, native_display, int_attribs);
    free(int_attribs);
    return display;
@@ -786,6 +790,9 @@ eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config,
    EGLSurface surface;
    EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
 
+   if (attrib_list && !int_attribs)
+      RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
+
    surface = eglCreatePlatformWindowSurfaceEXT(dpy, config, native_window,
                                                int_attribs);
    free(int_attribs);
@@ -854,6 +861,9 @@ eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config,
    EGLSurface surface;
    EGLint *int_attribs = _eglConvertAttribsToInt(attrib_list);
 
+   if (attrib_list && !int_attribs)
+      RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_SURFACE);
+
    surface = eglCreatePlatformPixmapSurfaceEXT(dpy, config, native_pixmap,
                                                int_attribs);
    free(int_attribs);
@@ -1343,6 +1353,9 @@ eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target,
    EGLImage image;
    EGLint *int_attribs = _eglConvertAttribsToInt(attr_list);
 
+   if (attr_list && !int_attribs)
+      RETURN_EGL_ERROR(NULL, EGL_BAD_ALLOC, EGL_NO_IMAGE);
+
    image = eglCreateImageKHR(dpy, ctx, target, buffer, int_attribs);
    free(int_attribs);
    return image;
-- 
2.1.0



More information about the mesa-dev mailing list