[Mesa-dev] [PATCH 1/2] drisw: Do error checking in XCreateDrawable

Chad Versace chad at chad-versace.us
Fri Jun 24 18:17:21 PDT 2011


If a calleé returns null, then free local memory and return false.

Cc: nobled at dreamwidth.org
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=33758
Note: This is a candidate for the stable branch.
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 src/glx/drisw_glx.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 07d4955..282b7f7 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -23,6 +23,7 @@
 
 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
 
+#include <stdbool.h>
 #include <X11/Xlib.h>
 #include "glxclient.h"
 #include <dlfcn.h>
@@ -89,6 +90,11 @@ XCreateDrawable(struct drisw_drawable * pdp,
    visTemp.visualid = visualid;
    visMask = (VisualScreenMask | VisualIDMask);
    pdp->visinfo = XGetVisualInfo(dpy, visMask, &visTemp, &num_visuals);
+   if (!pdp->visinfo) {
+      XFreeGC(dpy, pdp->gc);
+      XFreeGC(dpy, pdp->swapgc);
+      return False;
+   }
 
    /* create XImage */
    pdp->ximage = XCreateImage(dpy,
@@ -99,6 +105,12 @@ XCreateDrawable(struct drisw_drawable * pdp,
                               0, 0,                   /* width, height */
                               32,                     /* bitmap_pad */
                               0);                     /* bytes_per_line */
+   if (!pdp->ximage) {
+      XFreeGC(dpy, pdp->gc);
+      XFreeGC(dpy, pdp->swapgc);
+      Xfree(pdp->visinfo);
+      return False;
+   }
 
    return True;
 }
@@ -356,6 +368,7 @@ static __GLXDRIdrawable *
 driswCreateDrawable(struct glx_screen *base, XID xDrawable,
 		    GLXDrawable drawable, struct glx_config *modes)
 {
+   bool ok;
    struct drisw_drawable *pdp;
    __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
    struct drisw_screen *psc = (struct drisw_screen *) base;
@@ -375,7 +388,11 @@ driswCreateDrawable(struct glx_screen *base, XID xDrawable,
    pdp->base.drawable = drawable;
    pdp->base.psc = &psc->base;
 
-   XCreateDrawable(pdp, psc->base.dpy, xDrawable, modes->visualID);
+   ok = XCreateDrawable(pdp, psc->base.dpy, xDrawable, modes->visualID);
+   if (!ok) {
+      Xfree(pdp);
+      return NULL;
+   }
 
    /* Create a new drawable */
    pdp->driDrawable =
-- 
1.7.5.4



More information about the mesa-dev mailing list