<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH] mutt_gen_msgid() allocates the msgid off of the heap



On Tuesday, 16 December 2008 at 14:33, Erik Hovland wrote:
> 1 file changed, 5 insertions(+), 2 deletions(-)
> sendlib.c |    7 +++++--
> 
> 
> # HG changeset patch
> # User Erik Hovland <erik@xxxxxxxxxxx>
> # Date 1229466703 28800
> # Branch HEAD
> # Node ID cc483a58bfbda95208eded019fe620297f31a76d
> # Parent  94317019739335b9869b4e3f9c4cfef689dda58b
> mutt_gen_msgid() allocates the msgid off of the heap.
> 
> Since mutt_gen_msgid() allocates the msgid string with
> strdup, it is getting it off of the heap.
> 
> When the fprintf writes the msgid, the string is no longer
> tracked and that string is leaked.
> 
> diff --git a/sendlib.c b/sendlib.c
> --- a/sendlib.c
> +++ b/sendlib.c
> @@ -2342,6 +2342,7 @@
>    if ((f = safe_fopen (tempfile, "w")) != NULL)
>    {
>      int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
> +    char* msgid_str;
>      
>      if (!option (OPTBOUNCEDELIVERED))
>        ch_flags |= CH_WEED_DELIVERED;
> @@ -2349,13 +2350,15 @@
>      fseeko (fp, h->offset, 0);
>      fprintf (f, "Resent-From: %s", resent_from);
>      fprintf (f, "\nResent-%s", mutt_make_date (date, sizeof(date)));
> -    fprintf (f, "Resent-Message-ID: %s\n", mutt_gen_msgid());
> +    msgid_str = mutt_gen_msgid();
> +    fprintf (f, "Resent-Message-ID: %s\n", msgid_str);
>      fputs ("Resent-To: ", f);
>      mutt_write_address_list (to, f, 11, 0);
>      mutt_copy_header (fp, h, f, ch_flags, NULL);
>      fputc ('\n', f);
>      mutt_copy_bytes (fp, f, h->content->length);
> -    fclose (f);
> +    safe_fclose (&f);
> +    safe_free (&msgid_str);

Applied, thanks! We usually use the FREE macro instead of safe_free
though. You might want to give check_sec.sh (in the repository) a
whirl.