unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] notmuch_message_file_get_header: replace free with g_free
@ 2012-12-11  1:19 david
  2012-12-11  3:33 ` [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime david
  2012-12-11  4:50 ` [PATCH] notmuch_message_file_get_header: replace free with g_free Tomi Ollila
  0 siblings, 2 replies; 6+ messages in thread
From: david @ 2012-12-11  1:19 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

From: David Bremner <bremner@debian.org>

The pointer returned by g_mime_utils_header_decode_text is from the
following line in rfc2047_decode_tokens

	return g_string_free (decoded, FALSE);

The docs for g_string_free say

 Frees the memory allocated for the GString. If free_segment is TRUE
 it also frees the character data. If it's FALSE, the caller gains
 ownership of the buffer and must free it after use with g_free().
---
 lib/message-file.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index 915aba8..976769d 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -341,7 +341,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
 		strncpy(combined_header,header_sofar,hdrsofar);
 		*(combined_header+hdrsofar) = ' ';
 		strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);
-		free (decoded_value);
+		g_free (decoded_value);
 		g_hash_table_insert (message->headers, header, combined_header);
 	    }
 	} else {
@@ -350,7 +350,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
 		g_hash_table_insert (message->headers, header, decoded_value);
 	    } else {
 		free (header);
-		free (decoded_value);
+		g_free (decoded_value);
 		decoded_value = header_sofar;
 	    }
 	}
-- 
1.7.10.4

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

* [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime.
  2012-12-11  1:19 [PATCH] notmuch_message_file_get_header: replace free with g_free david
@ 2012-12-11  3:33 ` david
  2012-12-11  4:55   ` Tomi Ollila
                     ` (2 more replies)
  2012-12-11  4:50 ` [PATCH] notmuch_message_file_get_header: replace free with g_free Tomi Ollila
  1 sibling, 3 replies; 6+ messages in thread
From: david @ 2012-12-11  3:33 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

From: David Bremner <bremner@debian.org>

Apparently as of GMime 2.4, you don't need to call
internet_address_list_destroy anymore, but you still need to call
g_object_unref (from the GMime Changelog).

On the medium performance corpus, valgrind shows "possibly lost"
leakage in "notmuch new" dropping from 7M to 300k.
---
 lib/index.cc |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/index.cc b/lib/index.cc
index da0e6ce..a2edd6d 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -484,12 +484,18 @@ mboxes is deprecated and may be removed in the future.\n", filename);
     }
 
     from = g_mime_message_get_sender (mime_message);
-    addresses = internet_address_list_parse_string (from);
 
-    _index_address_list (message, "from", addresses);
+    addresses = internet_address_list_parse_string (from);
+    if (addresses) {
+	_index_address_list (message, "from", addresses);
+	g_object_unref (addresses);
+    }
 
     addresses = g_mime_message_get_all_recipients (mime_message);
-    _index_address_list (message, "to", addresses);
+    if (addresses) {
+	_index_address_list (message, "to", addresses);
+	g_object_unref (addresses);
+    }
 
     subject = g_mime_message_get_subject (mime_message);
     _notmuch_message_gen_terms (message, "subject", subject);
-- 
1.7.10.4

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

* Re: [PATCH] notmuch_message_file_get_header: replace free with g_free
  2012-12-11  1:19 [PATCH] notmuch_message_file_get_header: replace free with g_free david
  2012-12-11  3:33 ` [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime david
@ 2012-12-11  4:50 ` Tomi Ollila
  1 sibling, 0 replies; 6+ messages in thread
From: Tomi Ollila @ 2012-12-11  4:50 UTC (permalink / raw)
  To: david, notmuch; +Cc: David Bremner

On Tue, Dec 11 2012, david@tethera.net wrote:

> From: David Bremner <bremner@debian.org>
>
> The pointer returned by g_mime_utils_header_decode_text is from the
> following line in rfc2047_decode_tokens
>
> 	return g_string_free (decoded, FALSE);
>
> The docs for g_string_free say
>
>  Frees the memory allocated for the GString. If free_segment is TRUE
>  it also frees the character data. If it's FALSE, the caller gains
>  ownership of the buffer and must free it after use with g_free().
> ---

There is still some problem left: in the contex one can see the following
calls:

   g_hash_table_insert (message->headers, header, decoded_value);

and then

   combined_header = xmalloc(hdrsofar + newhdr + 2);
   strncpy(combined_header,header_sofar,hdrsofar);
   *(combined_header+hdrsofar) = ' ';
   strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);
   g_free (decoded_value);
   g_hash_table_insert (message->headers, header, combined_header);

Now, decoded_value should always be freed with g_free() and combined_header
with free(), note also that the hash table is initialized with:

   message->headers = g_hash_table_new_full (strcase_hash,
                                             strcase_equal,
                                             free,
                                             free);

i.e. finally the allocated string is freed with free() (in case
we're freeing... I did not look so far...).

Maybe all allocations and frees in the values of this header hash table
should be converted to use g_ -functions ? (or start to use talloc contex
there)


Tomi





>  lib/message-file.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/message-file.c b/lib/message-file.c
> index 915aba8..976769d 100644
> --- a/lib/message-file.c
> +++ b/lib/message-file.c
> @@ -341,7 +341,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
>  		strncpy(combined_header,header_sofar,hdrsofar);
>  		*(combined_header+hdrsofar) = ' ';
>  		strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);
> -		free (decoded_value);
> +		g_free (decoded_value);
>  		g_hash_table_insert (message->headers, header, combined_header);
>  	    }
>  	} else {
> @@ -350,7 +350,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
>  		g_hash_table_insert (message->headers, header, decoded_value);
>  	    } else {
>  		free (header);
> -		free (decoded_value);
> +		g_free (decoded_value);
>  		decoded_value = header_sofar;
>  	    }
>  	}
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime.
  2012-12-11  3:33 ` [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime david
@ 2012-12-11  4:55   ` Tomi Ollila
  2012-12-24 20:32   ` Austin Clements
  2012-12-24 23:06   ` David Bremner
  2 siblings, 0 replies; 6+ messages in thread
From: Tomi Ollila @ 2012-12-11  4:55 UTC (permalink / raw)
  To: david, notmuch; +Cc: David Bremner

On Tue, Dec 11 2012, david@tethera.net wrote:

> From: David Bremner <bremner@debian.org>
>
> Apparently as of GMime 2.4, you don't need to call
> internet_address_list_destroy anymore, but you still need to call
> g_object_unref (from the GMime Changelog).
>
> On the medium performance corpus, valgrind shows "possibly lost"
> leakage in "notmuch new" dropping from 7M to 300k.
> ---

LGTM.

Tomi


>  lib/index.cc |   12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/lib/index.cc b/lib/index.cc
> index da0e6ce..a2edd6d 100644
> --- a/lib/index.cc
> +++ b/lib/index.cc
> @@ -484,12 +484,18 @@ mboxes is deprecated and may be removed in the future.\n", filename);
>      }
>  
>      from = g_mime_message_get_sender (mime_message);
> -    addresses = internet_address_list_parse_string (from);
>  
> -    _index_address_list (message, "from", addresses);
> +    addresses = internet_address_list_parse_string (from);
> +    if (addresses) {
> +	_index_address_list (message, "from", addresses);
> +	g_object_unref (addresses);
> +    }
>  
>      addresses = g_mime_message_get_all_recipients (mime_message);
> -    _index_address_list (message, "to", addresses);
> +    if (addresses) {
> +	_index_address_list (message, "to", addresses);
> +	g_object_unref (addresses);
> +    }
>  
>      subject = g_mime_message_get_subject (mime_message);
>      _notmuch_message_gen_terms (message, "subject", subject);
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime.
  2012-12-11  3:33 ` [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime david
  2012-12-11  4:55   ` Tomi Ollila
@ 2012-12-24 20:32   ` Austin Clements
  2012-12-24 23:06   ` David Bremner
  2 siblings, 0 replies; 6+ messages in thread
From: Austin Clements @ 2012-12-24 20:32 UTC (permalink / raw)
  To: david, notmuch; +Cc: David Bremner

This patch LGTM.

On Mon, 10 Dec 2012, david@tethera.net wrote:
> From: David Bremner <bremner@debian.org>
>
> Apparently as of GMime 2.4, you don't need to call
> internet_address_list_destroy anymore, but you still need to call
> g_object_unref (from the GMime Changelog).
>
> On the medium performance corpus, valgrind shows "possibly lost"
> leakage in "notmuch new" dropping from 7M to 300k.
> ---
>  lib/index.cc |   12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/lib/index.cc b/lib/index.cc
> index da0e6ce..a2edd6d 100644
> --- a/lib/index.cc
> +++ b/lib/index.cc
> @@ -484,12 +484,18 @@ mboxes is deprecated and may be removed in the future.\n", filename);
>      }
>  
>      from = g_mime_message_get_sender (mime_message);
> -    addresses = internet_address_list_parse_string (from);
>  
> -    _index_address_list (message, "from", addresses);
> +    addresses = internet_address_list_parse_string (from);
> +    if (addresses) {
> +	_index_address_list (message, "from", addresses);
> +	g_object_unref (addresses);
> +    }
>  
>      addresses = g_mime_message_get_all_recipients (mime_message);
> -    _index_address_list (message, "to", addresses);
> +    if (addresses) {
> +	_index_address_list (message, "to", addresses);
> +	g_object_unref (addresses);
> +    }
>  
>      subject = g_mime_message_get_subject (mime_message);
>      _notmuch_message_gen_terms (message, "subject", subject);
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime.
  2012-12-11  3:33 ` [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime david
  2012-12-11  4:55   ` Tomi Ollila
  2012-12-24 20:32   ` Austin Clements
@ 2012-12-24 23:06   ` David Bremner
  2 siblings, 0 replies; 6+ messages in thread
From: David Bremner @ 2012-12-24 23:06 UTC (permalink / raw)
  To: notmuch

david@tethera.net writes:

> From: David Bremner <bremner@debian.org>
>
> Apparently as of GMime 2.4, you don't need to call
> internet_address_list_destroy anymore, but you still need to call
> g_object_unref (from the GMime Changelog).
>

pushed, 

d

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

end of thread, other threads:[~2012-12-24 23:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-11  1:19 [PATCH] notmuch_message_file_get_header: replace free with g_free david
2012-12-11  3:33 ` [PATCH] _notmuch_message_index_file: unref (free) address lists from gmime david
2012-12-11  4:55   ` Tomi Ollila
2012-12-24 20:32   ` Austin Clements
2012-12-24 23:06   ` David Bremner
2012-12-11  4:50 ` [PATCH] notmuch_message_file_get_header: replace free with g_free Tomi Ollila

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).