From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 0C8C16DE16DA for ; Sat, 18 Mar 2017 10:51:02 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZsWbF7p6KwjJ for ; Sat, 18 Mar 2017 10:51:01 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 834A76DE16D7 for ; Sat, 18 Mar 2017 10:50:54 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1cpIUU-0001Pe-W0; Sat, 18 Mar 2017 13:50:11 -0400 Received: (nullmailer pid 15959 invoked by uid 1000); Sat, 18 Mar 2017 17:50:46 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 3/6] fix memory leaks in notmuch-show.c:format_headers_sprinter() Date: Sat, 18 Mar 2017 14:50:35 -0300 Message-Id: <20170318175038.15887-4-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170318175038.15887-1-david@tethera.net> References: <20170318175038.15887-1-david@tethera.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Sat, 18 Mar 2017 17:51:02 -0000 From: Jeffrey Stedfast Internet_address_list_to_string() and g_mime_message_get_date_as_string() return allocated string buffers and not const, so from what I can tell from taking a look at the sprinter-sexp.c’s sexp_string() function, the code leaks the recipients_string as well as the date string. --- notmuch-show.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/notmuch-show.c b/notmuch-show.c index aff93803..095595e2 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -202,8 +202,9 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, * reflected in the file devel/schemata. */ InternetAddressList *recipients; - const char *recipients_string; + char *recipients_string; const char *reply_to_string; + char *date_string; sp->begin_map (sp); @@ -218,6 +219,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, if (recipients_string) { sp->map_key (sp, "To"); sp->string (sp, recipients_string); + g_free (recipients_string); } recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); @@ -225,6 +227,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, if (recipients_string) { sp->map_key (sp, "Cc"); sp->string (sp, recipients_string); + g_free (recipients_string); } recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC); @@ -232,6 +235,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, if (recipients_string) { sp->map_key (sp, "Bcc"); sp->string (sp, recipients_string); + g_free (recipients_string); } reply_to_string = g_mime_message_get_reply_to (message); @@ -248,7 +252,9 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message, sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References")); } else { sp->map_key (sp, "Date"); - sp->string (sp, g_mime_message_get_date_as_string (message)); + date_string = g_mime_message_get_date_as_string (message); + sp->string (sp, date_string); + g_free (date_string); } sp->end (sp); -- 2.11.0