Enlightenment CVS committal

Author  : ningerso
Project : e17
Module  : libs/imlib2

Dir     : e17/libs/imlib2/src/lib


Modified Files:
        api.c grab.c 


Log Message:
Protect against segfaults if XImage allocation fails.
Return usable status to the API caller so it can handle the error condition.

===================================================================
RCS file: /cvs/e/e17/libs/imlib2/src/lib/api.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- api.c       20 Oct 2006 18:21:24 -0000      1.10
+++ api.c       15 Feb 2007 04:15:03 -0000      1.11
@@ -2155,14 +2155,22 @@
      }
    im = __imlib_CreateImage(width, height, NULL);
    im->data = malloc(width * height * sizeof(DATA32));
-   __imlib_GrabDrawableToRGBA(im->data, 0, 0, width, height, ctx->display,
-                              ctx->drawable, mask, ctx->visual, ctx->colormap,
-                              ctx->depth, x, y, width, height, &domask,
-                              need_to_grab_x);
-   if (domask)
-      SET_FLAG(im->flags, F_HAS_ALPHA);
+   if (__imlib_GrabDrawableToRGBA(im->data, 0, 0, width, height, ctx->display,
+                                  ctx->drawable, mask, ctx->visual,
+                                 ctx->colormap, ctx->depth, x, y, width,
+                                 height, &domask, need_to_grab_x))
+     {
+       if (domask)
+          SET_FLAG(im->flags, F_HAS_ALPHA);
+       else
+          UNSET_FLAG(im->flags, F_HAS_ALPHA);
+     }
    else
-      UNSET_FLAG(im->flags, F_HAS_ALPHA);
+     {
+       __imlib_FreeImage(im);
+       im = NULL;
+     }
+
    return (Imlib_Image) im;
 }
 
===================================================================
RCS file: /cvs/e/e17/libs/imlib2/src/lib/grab.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- grab.c      20 May 2006 10:43:49 -0000      1.5
+++ grab.c      15 Feb 2007 04:15:03 -0000      1.6
@@ -729,6 +729,12 @@
      }
    if (!is_shm)
       xim = XGetImage(d, p, x, y, w, h, 0xffffffff, ZPixmap);
+   if (!xim)
+     {
+        if (grab)
+           XUngrabServer(d);
+       return 0;
+     }
 
    if ((m) && (domask))
      {



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to