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

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Tue Dec 13 05:08:00 PST 2011


On Tue, 13 Dec 2011 14:03:33 +0200, Tomi Ollila <tomi.ollila at iki.fi> wrote:
> 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);

Why can't we do this inside the if (charset) block?

Regards,
  Dmitry

>      if (stream_filter)
>  	g_object_unref(stream_filter);
>  }
> -- 
> 1.7.6.1
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list