unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] notmuch: unref charset_filter to fix one memory leak
@ 2011-12-13 12:03 Tomi Ollila
  2011-12-13 13:08 ` Dmitry Kurochkin
  0 siblings, 1 reply; 5+ messages in thread
From: Tomi Ollila @ 2011-12-13 12:03 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] notmuch: unref charset_filter to fix one memory leak
  2011-12-13 12:03 [PATCH] notmuch: unref charset_filter to fix one memory leak Tomi Ollila
@ 2011-12-13 13:08 ` Dmitry Kurochkin
  2011-12-13 18:18   ` [PATCH] notmuch: unref charset_filter (once more) " tomi.ollila
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Kurochkin @ 2011-12-13 13:08 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

On Tue, 13 Dec 2011 14:03:33 +0200, Tomi Ollila <tomi.ollila@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@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] notmuch: unref charset_filter (once more) to fix one memory leak
  2011-12-13 13:08 ` Dmitry Kurochkin
@ 2011-12-13 18:18   ` tomi.ollila
  2011-12-13 18:24     ` Dmitry Kurochkin
  2011-12-15 11:42     ` David Bremner
  0 siblings, 2 replies; 5+ messages in thread
From: tomi.ollila @ 2011-12-13 18:18 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

From: Tomi Ollila <tomi.ollila@iki.fi>

In my test case added g_object_unref(charset_filter) reduces memory
consumption over 90% when 'notmuch show --format=text "*"' is
executed (~11000 messages, RES ~330M -> ~25M).
---
Thanks Dmitry. I did not realize unref unreferences, does not deallocate
memory/data structures. g_mime_stream_filter_add() takes an additional
reference to the charset_filter object.
 notmuch-show.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 873a7c4..8da3295 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -471,9 +471,12 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
 	/* This result can be NULL for things like "unknown-8bit".
 	 * Don't set a NULL filter as that makes GMime print
 	 * annoying assertion-failure messages on stderr. */
-	if (charset_filter)
+	if (charset_filter) {
 	    g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter),
 				      charset_filter);
+	    g_object_unref (charset_filter);
+	}
+
     }
 
     wrapper = g_mime_part_get_content_object (GMIME_PART (part));
-- 
1.7.6.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] notmuch: unref charset_filter (once more) to fix one memory leak
  2011-12-13 18:18   ` [PATCH] notmuch: unref charset_filter (once more) " tomi.ollila
@ 2011-12-13 18:24     ` Dmitry Kurochkin
  2011-12-15 11:42     ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry Kurochkin @ 2011-12-13 18:24 UTC (permalink / raw)
  To: tomi.ollila, notmuch; +Cc: Tomi Ollila

On Tue, 13 Dec 2011 20:18:48 +0200, tomi.ollila@iki.fi wrote:
> From: Tomi Ollila <tomi.ollila@iki.fi>
> 
> In my test case added g_object_unref(charset_filter) reduces memory
> consumption over 90% when 'notmuch show --format=text "*"' is
> executed (~11000 messages, RES ~330M -> ~25M).
> ---
> Thanks Dmitry. I did not realize unref unreferences, does not deallocate
> memory/data structures. g_mime_stream_filter_add() takes an additional
> reference to the charset_filter object.

Looks good to me.

Regards,
  Dmitry

>  notmuch-show.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/notmuch-show.c b/notmuch-show.c
> index 873a7c4..8da3295 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -471,9 +471,12 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out)
>  	/* This result can be NULL for things like "unknown-8bit".
>  	 * Don't set a NULL filter as that makes GMime print
>  	 * annoying assertion-failure messages on stderr. */
> -	if (charset_filter)
> +	if (charset_filter) {
>  	    g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter),
>  				      charset_filter);
> +	    g_object_unref (charset_filter);
> +	}
> +
>      }
>  
>      wrapper = g_mime_part_get_content_object (GMIME_PART (part));
> -- 
> 1.7.6.1
> 
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] notmuch: unref charset_filter (once more) to fix one memory leak
  2011-12-13 18:18   ` [PATCH] notmuch: unref charset_filter (once more) " tomi.ollila
  2011-12-13 18:24     ` Dmitry Kurochkin
@ 2011-12-15 11:42     ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: David Bremner @ 2011-12-15 11:42 UTC (permalink / raw)
  To: tomi.ollila, notmuch; +Cc: Tomi Ollila

On Tue, 13 Dec 2011 20:18:48 +0200, tomi.ollila@iki.fi wrote:
> From: Tomi Ollila <tomi.ollila@iki.fi>
> 
> In my test case added g_object_unref(charset_filter) reduces memory
> consumption over 90% when 'notmuch show --format=text "*"' is
> executed (~11000 messages, RES ~330M -> ~25M).

pushed

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-15 11:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-13 12:03 [PATCH] notmuch: unref charset_filter to fix one memory leak Tomi Ollila
2011-12-13 13:08 ` Dmitry Kurochkin
2011-12-13 18:18   ` [PATCH] notmuch: unref charset_filter (once more) " tomi.ollila
2011-12-13 18:24     ` Dmitry Kurochkin
2011-12-15 11:42     ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).