Plug leaks of color conversion arrays in Do_Direct 81/9581/1
authorAlan Coopersmith <alan.coopersmith@sun.com>
Sun, 3 May 2009 23:19:38 +0000 (16:19 -0700)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 3 Sep 2013 04:25:51 +0000 (00:25 -0400)
[This bug was found by the Parfait bug checking tool.
 For more information see http://research.sun.com/projects/parfait ]

Change-Id: I753ab1fbb211966f9b5e45fa234fd53685233409
Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
xwud.c

diff --git a/xwud.c b/xwud.c
index 1c83b7b..5ab8613 100644 (file)
--- a/xwud.c
+++ b/xwud.c
@@ -1026,6 +1026,8 @@ Do_Direct(Display *dpy, XWDFileHeader *header, Colormap *colormap,
     if (in_image->depth <= 12) {
        pix = 1 << in_image->depth;
        pixels = (unsigned long *)malloc(sizeof(unsigned long) * pix);
+       if (pixels == NULL)
+           Error("Unable to allocate memory for pixel conversion");
        for (i = 0; i < pix; i++)
            pixels[i] = ~0L;
        color.flags = DoRed | DoGreen | DoBlue;
@@ -1057,6 +1059,7 @@ Do_Direct(Display *dpy, XWDFileHeader *header, Colormap *colormap,
                XPutPixel(out_image, x, y, color.pixel);
            }
        }
+       free(pixels);
     } else if (header->visual_class == TrueColor &&
               vinfo->class == TrueColor) {
        ormask = vinfo->red_mask;
@@ -1092,6 +1095,8 @@ Do_Direct(Display *dpy, XWDFileHeader *header, Colormap *colormap,
        pix = 1 << 12;
        pixels = (unsigned long *)malloc(sizeof(unsigned long) * pix);
        rpixels = (unsigned long *)malloc(sizeof(unsigned long) * pix);
+       if ((pixels == NULL) || (rpixels == NULL))
+           Error("Unable to allocate memory for pixel conversion");
        for (i = 0; i < pix; i++) {
            pixels[i] = ~0L;
            rpixels[i] = ~0L;
@@ -1128,6 +1133,8 @@ Do_Direct(Display *dpy, XWDFileHeader *header, Colormap *colormap,
                XPutPixel(out_image, x, y, color.pixel);
            }
        }
+       free(pixels);
+       free(rpixels);
     }
 }