Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id EEBAF431FBC for ; Mon, 10 Dec 2012 20:51:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9ijrhsgKAGjp for ; Mon, 10 Dec 2012 20:50:57 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 71D9B431FB6 for ; Mon, 10 Dec 2012 20:50:55 -0800 (PST) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id CB7A110007E; Tue, 11 Dec 2012 06:50:49 +0200 (EET) From: Tomi Ollila To: david@tethera.net, notmuch@notmuchmail.org Subject: Re: [PATCH] notmuch_message_file_get_header: replace free with g_free In-Reply-To: <1355188740-6663-1-git-send-email-david@tethera.net> References: <1355188740-6663-1-git-send-email-david@tethera.net> User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2012 04:51:01 -0000 On Tue, Dec 11 2012, david@tethera.net wrote: > From: David Bremner > > 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