[PATCH:app/bitmap] Fix pixmap leak in error paths of BWGetUnzoomedPixmap

Alan Coopersmith alan.coopersmith at oracle.com
Wed May 30 07:36:53 PDT 2012


Found by Parfait 0.5.0.1 bug checking tool:
   Leaked X Resource pix
        at line 393 of Bitmap.c in function 'BWGetUnzoomedPixmap'.
          pix initialized at line 388 with XCreatePixmap(...).
        at line 414 of Bitmap.c in function 'BWGetUnzoomedPixmap'.
          pix initialized at line 409 with XCreatePixmap(...).

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 Bitmap.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Bitmap.c b/Bitmap.c
index 8171bef..704cb98 100644
--- a/Bitmap.c
+++ b/Bitmap.c
@@ -389,8 +389,10 @@ BWGetUnzoomedPixmap(Widget w)
 			    BW->bitmap.zoom.image->width,
 			    BW->bitmap.zoom.image->height, 1);
 	if (!(gc = XCreateGC(XtDisplay(w), pix,
-			     (unsigned long) 0, (XGCValues *) 0)))
+			     (unsigned long) 0, (XGCValues *) 0))) {
+	    XFreePixmap(XtDisplay(w), pix);
 	    return (Pixmap) None;
+	}
 
 	XPutImage(XtDisplay(w), pix, gc,
 		  BW->bitmap.zoom.image,
@@ -410,8 +412,10 @@ BWGetUnzoomedPixmap(Widget w)
 			    BW->bitmap.image->width,
 			    BW->bitmap.image->height, 1);
 	if (! (gc = XCreateGC(XtDisplay(w), pix,
-			      (unsigned long) 0, (XGCValues *) 0)))
+			      (unsigned long) 0, (XGCValues *) 0))){
+	    XFreePixmap(XtDisplay(w), pix);
 	    return (Pixmap) None;
+	}
 
 	XPutImage(XtDisplay(w), pix, gc,
 		  BW->bitmap.image,
-- 
1.7.9.2



More information about the xorg-devel mailing list