Re: [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header

Subject: Re: [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header

Date: Mon, 08 Nov 2010 09:19:49 -0800

To: Michael Forney, notmuch@notmuchmail.org

Cc:

From: Carl Worth


On Thu,  4 Nov 2010 20:49:35 -0700, Michael Forney <mforney@mforney.org> wrote:
> When decoded_value, header_sofar, and header are unused, they should
> be freed.

Thanks for the cleanups here. Just looking over the patch it's clear
that I let some code into message-file.c without coercing the style into
what I would really prefer to see, (should use talloc more, should move
away from overly-abbreviated identifiers such as "hdrsofar", and
shouldn't have ambiguously named identifiers such as "header_sofar" and
"hdrsofar").

> +		free(decoded_value);
> +		free(header_sofar);
>  		g_hash_table_insert (message->headers, header, combined_header);
>  	    }
>  	} else {
>  	    if (header_sofar == NULL) {
>  		/* Only insert if we don't have a value for this header, yet. */
>  		g_hash_table_insert (message->headers, header, decoded_value);
> +	    } else {
> +		free(header);
> +		free(decoded_value);

But I didn't push the change yet. The above do look like memory leak
fixes as described in the commit message.

>  	if (match && !is_received)
> -	    return decoded_value;
> +	    return header_sofar == NULL ? decoded_value : header_sofar;
>      }

But this part looks like an independent bug fix that needs its own
description, (and perhaps a test case?). Could you please split the
patch into two?

Thanks,

-Carl

-- 
carl.d.worth@intel.com
part-000.sig (application/pgp-signature)

Thread: