[PATCH] notmuch: unref charset_filter to fix one memory leak

Tomi Ollila tomi.ollila at iki.fi
Tue Dec 13 04:03:33 PST 2011


In my use case g_object_unref(charset_filter) reduces memory
consumption over 90% when 'notmuch show --format=text "*"' is
executed (~11000 messages, RES ~330M -> ~25M).
---
 notmuch-show.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 873a7c4..23d7368 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -450,6 +450,7 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
 {
     GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
     GMimeStream *stream_filter = NULL;
+    GMimeFilter *charset_filter = NULL;
     GMimeDataWrapper *wrapper;
     const char *charset;
 
@@ -466,7 +467,6 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
 
     charset = g_mime_object_get_content_type_parameter (part, "charset");
     if (charset) {
-	GMimeFilter *charset_filter;
 	charset_filter = g_mime_filter_charset_new (charset, "UTF-8");
 	/* This result can be NULL for things like "unknown-8bit".
 	 * Don't set a NULL filter as that makes GMime print
@@ -479,6 +479,8 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
     wrapper = g_mime_part_get_content_object (GMIME_PART (part));
     if (wrapper && stream_filter)
 	g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
+    if (charset_filter)
+	g_object_unref (charset_filter);
     if (stream_filter)
 	g_object_unref(stream_filter);
 }
-- 
1.7.6.1


More information about the notmuch mailing list