[PATCH] Release memory allocated by internet_address_list_parse_string()

Tomi Ollila tomi.ollila at iki.fi
Wed Dec 7 13:29:52 PST 2011


On Wed, 07 Dec 2011 22:13:19 +0200, Tomi Ollila <tomi.ollila at iki.fi> wrote:
> g_object_unref() releases the memory of the InternetAddressList object
> returned by internet_address_list_parse_string() -- when last (only)
> reference is released, internet_address_list_finalize() will do cleanup.
> ---
> When reviewing, see also gmime-2.4.25/gmime/internet-address.c (or older)
> I tested this patch by entering:  notmuch show --format=mbox '*' | wc
> 
> Note that this fixes one potential memory leak only in case --format=mbox
> as _extract_email_address is called only there.

There is at least one bug here -- I failed to check whether addresses
is non-NULL before attempting to g_object_unref (). So please ignore
that when reviewing whether g_object_unref() is the correct action here.

I provide a new patch when I know whether re-check or separate the
NULL test in the beginning of _extract_email_address().

>  notmuch-show.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/notmuch-show.c b/notmuch-show.c
> index 603992a..3abfa07 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -255,7 +255,7 @@ _extract_email_address (const void *ctx, const char *from)
>      email = talloc_strdup (ctx, email);
>  
>    DONE:
> -    /* XXX: How to free addresses here? */
> +    g_object_unref (addresses);
>      return email;
>     }
>  
> -- 
> 1.7.7.3

Tomi


More information about the notmuch mailing list