free stuff earlier, when they're no longer used
[xmenu] / xmenu.c
diff --git a/xmenu.c b/xmenu.c
index d6b2cde..d557f6d 100644 (file)
--- a/xmenu.c
+++ b/xmenu.c
@@ -316,6 +316,8 @@ initmonitor(void)
                mon.y = info[selmon].y_org;
                mon.w = info[selmon].width;
                mon.h = info[selmon].height;
                mon.y = info[selmon].y_org;
                mon.w = info[selmon].width;
                mon.h = info[selmon].height;
+
+               XFree(info);
        }
 
        if (!pflag) {
        }
 
        if (!pflag) {
@@ -331,9 +333,9 @@ initmonitor(void)
 static void
 initresources(void)
 {
 static void
 initresources(void)
 {
-       char *xrm;
        long n;
        char *type;
        long n;
        char *type;
+       char *xrm;
        XrmDatabase xdb;
        XrmValue xval;
 
        XrmDatabase xdb;
        XrmValue xval;
 
@@ -574,8 +576,6 @@ parsestdin(void)
                        file = label + 4;
                        label = strtok(NULL, "\t\n");
                }
                        file = label + 4;
                        label = strtok(NULL, "\t\n");
                }
-               if (file && *file == '\0')
-                       errx(1, "blank icon filename");
 
                /* get the output */
                output = strtok(NULL, "\n");
 
                /* get the output */
                output = strtok(NULL, "\n");
@@ -897,7 +897,10 @@ loadicon(const char *file)
        int imgsize;
 
        icon = imlib_load_image_with_error_return(file, &errcode);
        int imgsize;
 
        icon = imlib_load_image_with_error_return(file, &errcode);
-       if (icon == NULL) {
+       if (*file == '\0') {
+               warnx("could not load icon (file name is blank)");
+               return NULL;
+       } else if (icon == NULL) {
                switch (errcode) {
                case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
                        errstr = "file does not exist";
                switch (errcode) {
                case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
                        errstr = "file does not exist";
@@ -933,7 +936,8 @@ loadicon(const char *file)
                        errstr = "unknown error";
                        break;
                }
                        errstr = "unknown error";
                        break;
                }
-               errx(1, "could not load icon (%s): %s", errstr, file);
+               warnx("could not load icon (%s): %s", errstr, file);
+               return NULL;
        }
 
        imlib_context_set_image(icon);
        }
 
        imlib_context_set_image(icon);
@@ -1011,15 +1015,21 @@ drawitems(struct Menu *menu)
                                             Convex, CoordModeOrigin);
                        }
 
                                             Convex, CoordModeOrigin);
                        }
 
-                       /* draw icon */
-                       if (item->file != NULL && !iflag) {
+                       /* try to load icon */
+                       if (item->file && !iflag) {
                                item->icon = loadicon(item->file);
                                item->icon = loadicon(item->file);
+                               free(item->file);
+                       }
 
 
+                       /* draw icon if properly loaded */
+                       if (item->icon) {
                                imlib_context_set_image(item->icon);
                                imlib_context_set_drawable(item->sel);
                                imlib_render_image_on_drawable(config.horzpadding, config.iconpadding);
                                imlib_context_set_drawable(item->unsel);
                                imlib_render_image_on_drawable(config.horzpadding, config.iconpadding);
                                imlib_context_set_image(item->icon);
                                imlib_context_set_drawable(item->sel);
                                imlib_render_image_on_drawable(config.horzpadding, config.iconpadding);
                                imlib_context_set_drawable(item->unsel);
                                imlib_render_image_on_drawable(config.horzpadding, config.iconpadding);
+                               imlib_context_set_image(item->icon);
+                               imlib_free_image();
                        }
                }
        }
                        }
                }
        }
@@ -1311,13 +1321,6 @@ cleanmenu(struct Menu *menu)
                if (tmp->label != tmp->output)
                        free(tmp->label);
                free(tmp->output);
                if (tmp->label != tmp->output)
                        free(tmp->label);
                free(tmp->output);
-               if (tmp->file != NULL) {
-                       free(tmp->file);
-                       if (tmp->icon != NULL) {
-                               imlib_context_set_image(tmp->icon);
-                               imlib_free_image();
-                       }
-               }
                item = item->next;
                free(tmp);
        }
                item = item->next;
                free(tmp);
        }