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 58B8D6DE1401 for ; Fri, 17 Mar 2017 13:20:47 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.499 X-Spam-Level: X-Spam-Status: No, score=0.499 tagged_above=-999 required=5 tests=[AWL=-0.153, SPF_NEUTRAL=0.652] 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 lyr1yNB-YAbi for ; Fri, 17 Mar 2017 13:20:46 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id E477F6DE13FC for ; Fri, 17 Mar 2017 13:20:45 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 6ACE810008D; Fri, 17 Mar 2017 22:20:03 +0200 (EET) From: Tomi Ollila To: Jeffrey Stedfast , "notmuch\@notmuchmail.org" Subject: Re: [PATCH] fix memory leaks in notmuch-show.c:format_headers_sprinter() In-Reply-To: <35A18711-0D6B-4E93-A964-A07DAC406AED@microsoft.com> References: <35A18711-0D6B-4E93-A964-A07DAC406AED@microsoft.com> User-Agent: Notmuch/0.24+38~g4a0f2a1 (https://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Fri, 17 Mar 2017 20:20:47 -0000 On Thu, Mar 16 2017, Jeffrey Stedfast wrote: > Hey guys, > > Was just grepping through notmuch sources and discovered what I think are= memory leaks in notmuch-show.c=E2=80=99s format_headers_sprinter() code. > > 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=E2=80=99s sexp_string() functio= n, the > code leaks the recipients_string as well as the date string. Change looks good, tests pass (it even applied with git am). The commit message could be amended like so, that subject line and the paragraph above this were left... Tomi > > Attached is a patch which fixes these leaks. > > Hope this helps, > > Jeff > > > 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. */ >=20=20 > InternetAddressList *recipients; > - const char *recipients_string; > + char *recipients_string; > const char *reply_to_string; > + char *date_string; >=20=20 > sp->begin_map (sp); >=20=20 > @@ -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); > } >=20=20 > recipients =3D g_mime_message_get_recipients (message, GMIME_RECIPIE= NT_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); > } >=20=20 > recipients =3D g_mime_message_get_recipients (message, GMIME_RECIPIE= NT_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); > } >=20=20 > reply_to_string =3D 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), "Refe= rences")); > } else { > sp->map_key (sp, "Date"); > - sp->string (sp, g_mime_message_get_date_as_string (message)); > + date_string =3D g_mime_message_get_date_as_string (message); > + sp->string (sp, date_string); > + g_free (date_string); > } >=20=20 > sp->end (sp); > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch