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

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).