Fix some minor memleaks, fix crash on reload.
authorBrenden Matthews <brenden@diddyinc.com>
Sat, 2 Jan 2010 22:22:46 +0000 (14:22 -0800)
committerBrenden Matthews <brenden@diddyinc.com>
Sat, 2 Jan 2010 22:43:23 +0000 (14:43 -0800)
It seems that closing xft fonts on reload is a bad idea, but this seems
to result in a memory leak.  As far as I can tell, the leak doesn't grow
beyond the initial allocation however.

src/conky.c
src/fonts.c
src/llua.c
src/mail.c
src/x11.c

index 18224f9..8eab0e6 100644 (file)
@@ -3919,6 +3919,7 @@ static void main_loop(void)
                                                                        current_config,
                                                                        IN_MODIFY);
                                                }
+                                               break;
                                        }
 #ifdef HAVE_LUA
                                        else {
index 8767e00..6067bf2 100644 (file)
@@ -135,7 +135,13 @@ void free_fonts(void)
        for (i = 0; i <= font_count; i++) {
 #ifdef XFT
                if (use_xft) {
-                       XftFontClose(display, fonts[i].xftfont);
+                       /*
+                        * Do we not need to close fonts with Xft? Unsure.  Not freeing the
+                        * fonts seems to incur a slight memory leak, but it also prevents
+                        * a crash.
+                        *
+                        * XftFontClose(display, fonts[i].xftfont);
+                        */
                        fonts[i].xftfont = 0;
                } else
 #endif /* XFT */
index 21ac7d2..652bfa0 100644 (file)
@@ -303,6 +303,14 @@ void llua_close(void)
                free(draw_post_hook);
                draw_post_hook = 0;
        }
+       if (startup_hook) {
+               free(startup_hook);
+               startup_hook = 0;
+       }
+       if (shutdown_hook) {
+               free(shutdown_hook);
+               shutdown_hook = 0;
+       }
        if(!lua_L) return;
        lua_close(lua_L);
        lua_L = NULL;
@@ -398,11 +406,13 @@ void llua_set_number(const char *key, double value)
 
 void llua_set_startup_hook(const char *args)
 {
+       if (startup_hook) free(startup_hook);
        startup_hook = strdup(args);
 }
 
 void llua_set_shutdown_hook(const char *args)
 {
+       if (shutdown_hook) free(shutdown_hook);
        shutdown_hook = strdup(args);
 }
 
index bfd80fe..02b4148 100644 (file)
@@ -816,7 +816,7 @@ static void *imap_thread(void *arg)
                                        recvbuf[numbytes] = '\0';
                                        DBGP2("imap_thread() received: %s", recvbuf);
                                        if (strlen(recvbuf) > 2) {
-                                               unsigned long messages, recent;
+                                               unsigned long messages, recent = 0;
                                                char *buf = recvbuf;
                                                char force_check = 0;
                                                buf = strstr(buf, "EXISTS");
index 62310a6..7892b96 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -238,11 +238,13 @@ static int get_argb_visual(Visual** visual, int *depth) {
                        *visual = visual_list[i].visual;
                        *depth = visual_list[i].depth;
                        DBGP("Found ARGB Visual");
+                       XFree(visual_list);
                        return 1;
                }
        }
        // no argb visual available
        DBGP("No ARGB Visual found");
+       XFree(visual_list);
        return 0;
 }
 #endif /* USE_ARGB */