The XPM Draw and Load functions store the unsigned char pointer in the
RImage src variables.

Now, the function argument srcdata is not used, so can be removed.

This patch also checks if the image->srcdata variable is empty. If is
empty, and the image is XPM is because the USE_XPM macro is undefined
and the nxpm.c file functions are used. In this case, the RImage
contains the image rendered and painted, so the RDrawXPM mustn't
continue.

Note that the XpmFreeXpmImage is not done now in xpm.c. This is because
the Xpm struct is used for other future images (see caching in load.c,
in the RLoad Function). If we free() the memory there, in xpm.c, then
the future cached images won't find the image, and wmaker will crash.
The memory is now freeded in raster.c, in RReleaseImage function.

Signed-off-by: Rodolfo García Peñas (kix) <[email protected]>
---
 wrlib/xpm.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/wrlib/xpm.c b/wrlib/xpm.c
index cca56f8..8f94ce8 100644
--- a/wrlib/xpm.c
+++ b/wrlib/xpm.c
@@ -33,7 +33,7 @@
 #include "wraster.h"
 #include "imgformat.h"
 
-RImage *RDrawXPM(RContext *context, RImage *image, unsigned char *srcdata)
+RImage *RDrawXPM(RContext *context, RImage *image)
 {
        Display *dpy = context->dpy;
        Colormap cmap = context->cmap;
@@ -43,17 +43,18 @@ RImage *RDrawXPM(RContext *context, RImage *image, unsigned 
char *srcdata)
        int *p;
        int i;
 
-       if ((context == NULL) || (image == NULL) || (srcdata == NULL)) {
+       if ((context == NULL) || (image == NULL)) {
                if (image)
                        RReleaseImage(image);
 
-               if (srcdata)
-                       free(srcdata);
-
                return NULL;
        }
 
-       xpm = (XpmImage *) srcdata;
+       /* xpm or nxpm. If nxpm srcdata is null, and the image is done */
+       if (image->srcdata == NULL)
+               return image;
+
+       xpm = (XpmImage *) image->srcdata;
 
        if (xpm->colorTable == NULL) {
                RErrorCode = RERR_BADIMAGEFILE;
@@ -132,8 +133,6 @@ RImage *RDrawXPM(RContext *context, RImage *image, unsigned 
char *srcdata)
        for (i = 0; i < 4; i++)
                free(color_table[i]);
 
-       XpmFreeXpmImage(xpm);
-
        return image;
 }
 
@@ -141,7 +140,6 @@ RImage *RGetImageFromXPMData(RContext *context, char 
**xpmData)
 {
        RImage *image;
        XpmImage xpm;
-       unsigned char *srcdata;
        int i;
 
        i = XpmCreateXpmImageFromData(xpmData, &xpm, (XpmInfo *) NULL);
@@ -177,9 +175,11 @@ RImage *RGetImageFromXPMData(RContext *context, char 
**xpmData)
 
        /* Add the XpmImage xpm as srcdata */
        image->srcformat = IM_XPM;
-       srcdata = (unsigned char *) malloc(sizeof(xpm));
-       memcpy(srcdata, &xpm, sizeof(xpm));
-       image = RDrawXPM(context, image, srcdata);
+       image->srcdatalen = sizeof(xpm);
+       image->srcdata = (unsigned char *) malloc(image->srcdatalen);
+       memcpy(image->srcdata, &xpm, image->srcdatalen);
+
+       image = RDrawXPM(context, image);
 
        return image;
 }
@@ -188,7 +188,6 @@ RImage *RLoadXPM(RContext *context, const char *file)
 {
        RImage *image;
        XpmImage xpm;
-       unsigned char *srcdata;
        int i;
 
        i = XpmReadFileToXpmImage((char *)file, &xpm, (XpmInfo *) NULL);
@@ -223,9 +222,11 @@ RImage *RLoadXPM(RContext *context, const char *file)
 
        /* Add the XpmImage xpm as srcdata */
        image->srcformat = IM_XPM;
-       srcdata = (unsigned char *) malloc(sizeof(xpm));
-       memcpy(srcdata, &xpm, sizeof(xpm));
-       image = RDrawXPM(context, image, srcdata);
+       image->srcdatalen = sizeof(xpm);
+       image->srcdata = (unsigned char *) malloc(image->srcdatalen);
+       memcpy(image->srcdata, &xpm, image->srcdatalen);
+
+       image = RDrawXPM(context, image);
 
        return image;
 }
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to