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 1D654431FAF for ; Fri, 21 Dec 2012 09:52:11 -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 CYVTCXvAN+QL for ; Fri, 21 Dec 2012 09:52:10 -0800 (PST) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id F4130431FAE for ; Fri, 21 Dec 2012 09:52:09 -0800 (PST) Received: by guru.guru-group.fi (Postfix, from userid 501) id 11DA01001F5; Fri, 21 Dec 2012 19:52:03 +0200 (EET) From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [PATCH 1/1] lib/message-file.c: use g_malloc () & g_free () in hash table values Date: Fri, 21 Dec 2012 19:52:01 +0200 Message-Id: <1356112321-6332-1-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.8.0 Cc: tomi.ollila@iki.fi 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: Fri, 21 Dec 2012 17:52:11 -0000 The message->headers hash table values get data returned by g_mime_utils_header_decode_text (). 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(). The remaining frees and allocations referencing to message->headers hash values have been changed to use g_free and g_malloc functions. This combines and completes the changes started by David Bremner. --- This was meant to be in reply to id:87mwxkptqn.fsf@zancas.localnet but I fumbled it. ;) lib/message-file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/message-file.c b/lib/message-file.c index 915aba8..4d9af89 100644 --- a/lib/message-file.c +++ b/lib/message-file.c @@ -111,7 +111,7 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename) message->headers = g_hash_table_new_full (strcase_hash, strcase_equal, free, - free); + g_free); message->parsing_started = 0; message->parsing_finished = 0; @@ -337,11 +337,11 @@ notmuch_message_file_get_header (notmuch_message_file_t *message, /* we need to add the header to those we already collected */ newhdr = strlen(decoded_value); hdrsofar = strlen(header_sofar); - combined_header = xmalloc(hdrsofar + newhdr + 2); + combined_header = g_malloc(hdrsofar + newhdr + 2); 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.8.0