From bbb267586acd8f6a3a28d0e9b3896467be339440 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Sat, 2 Jan 2010 14:22:46 -0800 Subject: [PATCH] Fix some minor memleaks, fix crash on reload. 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 | 1 + src/fonts.c | 8 +++++++- src/llua.c | 10 ++++++++++ src/mail.c | 2 +- src/x11.c | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/conky.c b/src/conky.c index 18224f9f..8eab0e60 100644 --- a/src/conky.c +++ b/src/conky.c @@ -3919,6 +3919,7 @@ static void main_loop(void) current_config, IN_MODIFY); } + break; } #ifdef HAVE_LUA else { diff --git a/src/fonts.c b/src/fonts.c index 8767e000..6067bf23 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -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 */ diff --git a/src/llua.c b/src/llua.c index 21ac7d25..652bfa0e 100644 --- a/src/llua.c +++ b/src/llua.c @@ -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); } diff --git a/src/mail.c b/src/mail.c index bfd80fe0..02b41485 100644 --- a/src/mail.c +++ b/src/mail.c @@ -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"); diff --git a/src/x11.c b/src/x11.c index 62310a6b..7892b964 100644 --- 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 */