unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header
@ 2010-11-05  3:49 Michael Forney
  2010-11-08 17:19 ` Carl Worth
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Forney @ 2010-11-05  3:49 UTC (permalink / raw)
  To: notmuch; +Cc: Michael Forney

When decoded_value, header_sofar, and header are unused, they should be freed.

---
 lib/message-file.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index 7722832..1d61577 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -341,18 +341,23 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
 		strncpy(combined_header,header_sofar,hdrsofar);
 		*(combined_header+hdrsofar) = ' ';
 		strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);
+		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);
 	    }
 	}
 	/* if we found a match we can bail - unless of course we are
 	 * collecting all the Received: headers */
 	if (match && !is_received)
-	    return decoded_value;
+	    return header_sofar == NULL ? decoded_value : header_sofar;
     }
 
     if (message->parsing_finished) {
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header
  2010-11-05  3:49 [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header Michael Forney
@ 2010-11-08 17:19 ` Carl Worth
  0 siblings, 0 replies; 2+ messages in thread
From: Carl Worth @ 2010-11-08 17:19 UTC (permalink / raw)
  To: Michael Forney, notmuch

[-- Attachment #1: Type: text/plain, Size: 1397 bytes --]

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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-08 17:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-05  3:49 [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header Michael Forney
2010-11-08 17:19 ` Carl Worth

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).