[PATCH] lib: Fix memory leaks in notmuch_message_file_get_header
Michael Forney
mforney at mforney.org
Thu Nov 4 20:49:35 PDT 2010
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
More information about the notmuch
mailing list