* mu-msg-gmime: fix leak when converting to utf8

This commit is contained in:
Dirk-Jan C. Binnema
2010-02-08 23:17:35 +02:00
parent e078512fb4
commit 9a4340406b

View File

@ -586,9 +586,11 @@ convert_to_utf8 (GMimePart *part, char *buffer)
/* of course, the charset specified may be incorrect... */ /* of course, the charset specified may be incorrect... */
if (charset) { if (charset) {
char *utf8 = text_to_utf8 (buffer, charset); char *utf8 = text_to_utf8 (buffer, charset);
if (utf8) if (utf8) {
g_free (buffer);
return utf8; return utf8;
} }
}
/* hmmm.... no charset at all, or conversion failed; ugly hack: /* hmmm.... no charset at all, or conversion failed; ugly hack:
* replace all non-ascii chars with '.' instead... TODO: come up * replace all non-ascii chars with '.' instead... TODO: come up
@ -604,19 +606,14 @@ stream_to_string (GMimeStream *stream, size_t buflen, gboolean convert_utf8)
char *buffer; char *buffer;
ssize_t bytes; ssize_t bytes;
buffer = (char*)malloc(buflen + 1); buffer = g_new(char, buflen + 1);
if (!buffer) {
g_warning ("%s: failed to allocate %u bytes", __FUNCTION__,
buflen);
return NULL;
}
g_mime_stream_reset (stream); g_mime_stream_reset (stream);
/* we read everything in one go */ /* we read everything in one go */
bytes = g_mime_stream_read (stream, buffer, buflen); bytes = g_mime_stream_read (stream, buffer, buflen);
if (bytes < 0) { if (bytes < 0) {
g_warning ("%s: failed to read from stream", __FUNCTION__); g_warning ("%s: failed to read from stream", __FUNCTION__);
free (buffer); g_free (buffer);
return NULL; return NULL;
} }
@ -667,7 +664,7 @@ cleanup:
static char* static char*
mu_msg_gmime_get_body (MuMsgGMime *msg, gboolean want_html) get_body (MuMsgGMime *msg, gboolean want_html)
{ {
GetBodyData data; GetBodyData data;
@ -698,8 +695,7 @@ mu_msg_gmime_get_body_html (MuMsgGMime *msg)
if (msg->_fields[HTML_FIELD]) if (msg->_fields[HTML_FIELD])
return msg->_fields[HTML_FIELD]; return msg->_fields[HTML_FIELD];
else else
return msg->_fields[HTML_FIELD] = return msg->_fields[HTML_FIELD] = get_body (msg, TRUE);
mu_msg_gmime_get_body (msg, TRUE);
} }
@ -711,8 +707,7 @@ mu_msg_gmime_get_body_text (MuMsgGMime *msg)
if (msg->_fields[TEXT_FIELD]) if (msg->_fields[TEXT_FIELD])
return msg->_fields[TEXT_FIELD]; return msg->_fields[TEXT_FIELD];
else else
return msg->_fields[TEXT_FIELD] = return msg->_fields[TEXT_FIELD] = get_body (msg, FALSE);
mu_msg_gmime_get_body (msg, FALSE);
} }