summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-04-14 18:23:42 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-04-14 18:23:42 +0300
commitdbbf8dae0bdd56d108f8bfda7614b4a3b895eae2 (patch)
tree75e2168e73ebb642bde137dfac1092a9c0b6483b
parent77b116b12786c1f9520e87868528494db61ce8af (diff)
downloadmailutils-dbbf8dae0bdd56d108f8bfda7614b4a3b895eae2.tar.gz
mailutils-dbbf8dae0bdd56d108f8bfda7614b4a3b895eae2.tar.bz2
Fix memory leaks in filter and filter_iconv code.
* mailbox/filter.c (filter_destroy): Destroy the underlying stream, unless flag is given. (mu_filter_create): Treat last argument as stream flags. * mailbox/filter_iconv.c (_icvt_destroy): Free the icvt_stream structure. * examples/mimetest.c (message_display_parts): Pass MU_STREAM_NO_CLOSE to the invocation of mu_filter_create. * mail/decode.c (display_submessage): Likewise. * mailbox/attachment.c (mu_message_save_attachment): Likewise. * mh/mh_list.c (eval_body): Likewise. * mh/mhn.c (mhn_message_size, show_internal): Likewise. (finish_text_msg): Likewise; call mu_stream_destroy * imap4d/preauth.c (decode64_buf): remove unnecessary call to mu_stream_destroy. * libmu_auth/ldap.c (chk_md5, chk_smd5) (chk_sha, chk_ssha): Likewise. * mailbox/mutil.c: Fix indentation.
-rw-r--r--examples/mimetest.c5
-rw-r--r--imap4d/preauth.c1
-rw-r--r--libmu_auth/ldap.c5
-rw-r--r--mail/decode.c3
-rw-r--r--mailbox/attachment.c3
-rw-r--r--mailbox/filter.c16
-rw-r--r--mailbox/filter_iconv.c1
-rw-r--r--mailbox/mutil.c4
-rw-r--r--mh/mh_list.c3
-rw-r--r--mh/mhn.c13
10 files changed, 31 insertions, 23 deletions
diff --git a/examples/mimetest.c b/examples/mimetest.c
index bca97af28..923e4d0ff 100644
--- a/examples/mimetest.c
+++ b/examples/mimetest.c
@@ -251,7 +251,10 @@ message_display_parts (mu_message_t msg, int indent)
printf ("%*.*sBegin\n", indent, indent, "");
mu_message_get_body (part, &body);
mu_body_get_stream (body, &str);
- mu_filter_create (&str, str, encoding, 0, 0);
+ /* Make sure the original body stream is not closed when
+ str gets destroyed */
+ mu_filter_create (&str, str, encoding, MU_FILTER_DECODE,
+ MU_STREAM_READ | MU_STREAM_NO_CLOSE);
offset = 0;
while (mu_stream_readline (str, buf, sizeof (buf),
offset, &nbytes) == 0 && nbytes)
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index a9a2a5cc1..203cb2958 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -217,7 +217,6 @@ decode64_buf (const char *name, unsigned char **pbuf, size_t *psize)
mu_stream_sequential_write (str, name, namelen);
mu_stream_read (flt, (char*) buf, sizeof buf, 0, &size);
mu_stream_destroy (&flt, NULL);
- mu_stream_destroy (&str, NULL);
*pbuf = malloc (size);
if (!*pbuf)
return 1;
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 70d3e0fc2..3fdedfbe5 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -602,7 +602,6 @@ chk_md5 (const char *db_pass, const char *pass)
mu_stream_read (flt, (char*) d1, sizeof d1, 0, NULL);
mu_stream_destroy (&flt, NULL);
- mu_stream_destroy (&str, NULL);
return memcmp (md5digest, d1, sizeof md5digest) == 0 ?
0 : MU_ERR_AUTH_FAILURE;
@@ -629,13 +628,11 @@ chk_smd5 (const char *db_pass, const char *pass)
if (!d1)
{
mu_stream_destroy (&flt, NULL);
- mu_stream_destroy (&str, NULL);
return ENOMEM;
}
mu_stream_read (flt, (char*) d1, size, 0, &size);
mu_stream_destroy (&flt, NULL);
- mu_stream_destroy (&str, NULL);
if (size <= 16)
{
@@ -674,7 +671,6 @@ chk_sha (const char *db_pass, const char *pass)
mu_stream_read (flt, (char*) d1, sizeof d1, 0, NULL);
mu_stream_destroy (&flt, NULL);
- mu_stream_destroy (&str, NULL);
return memcmp (sha1digest, d1, sizeof sha1digest) == 0 ?
0 : MU_ERR_AUTH_FAILURE;
@@ -701,7 +697,6 @@ chk_ssha (const char *db_pass, const char *pass)
if (!d1)
{
mu_stream_destroy (&flt, NULL);
- mu_stream_destroy (&str, NULL);
return ENOMEM;
}
diff --git a/mail/decode.c b/mail/decode.c
index 2eb3a8287..4beadc93f 100644
--- a/mail/decode.c
+++ b/mail/decode.c
@@ -258,7 +258,8 @@ display_submessage (struct mime_descend_closure *closure, void *data)
/* Can we decode. */
if (mu_filter_create(&d_stream, b_stream, closure->encoding,
- MU_FILTER_DECODE, MU_STREAM_READ) == 0)
+ MU_FILTER_DECODE,
+ MU_STREAM_READ|MU_STREAM_NO_CLOSE) == 0)
stream = d_stream;
else
stream = b_stream;
diff --git a/mailbox/attachment.c b/mailbox/attachment.c
index 26430fc93..8f02b4fbd 100644
--- a/mailbox/attachment.c
+++ b/mailbox/attachment.c
@@ -313,7 +313,8 @@ mu_message_save_attachment (mu_message_t msg, const char *filename,
content_encoding = "7bit";
ret =
mu_filter_create (&info->stream, istream, content_encoding,
- MU_FILTER_DECODE, MU_STREAM_READ);
+ MU_FILTER_DECODE,
+ MU_STREAM_READ | MU_STREAM_NO_CLOSE);
free (content_encoding_mem);
}
}
diff --git a/mailbox/filter.c b/mailbox/filter.c
index 6a2e4d11d..e7ad3d20b 100644
--- a/mailbox/filter.c
+++ b/mailbox/filter.c
@@ -46,6 +46,8 @@ static void
filter_destroy (mu_stream_t stream)
{
mu_filter_t filter = mu_stream_get_owner (stream);
+ if (!(stream->flags & MU_STREAM_NO_CLOSE))
+ mu_stream_destroy (&filter->stream, mu_stream_get_owner (filter->stream));
if (filter->_destroy)
filter->_destroy (filter);
if (filter->property)
@@ -165,7 +167,7 @@ mu_filter_get_list (mu_list_t *plist)
int
mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
- int type, int direction)
+ int type, int flags)
{
mu_iterator_t iterator = NULL;
mu_filter_record_t filter_record = NULL;
@@ -204,14 +206,12 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
if (found)
{
- int flags = 0;
mu_filter_t filter;
filter = calloc (1, sizeof (*filter));
if (filter == NULL)
return ENOMEM;
- mu_stream_get_flags (stream, &flags);
status = mu_stream_create (pstream, flags | MU_STREAM_NO_CHECK, filter);
if (status != 0)
{
@@ -221,7 +221,11 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
filter->stream = stream;
filter->filter_stream = *pstream;
- filter->direction = (direction == 0) ? MU_STREAM_READ : direction;
+ filter->direction = (flags == 0) ? MU_STREAM_READ
+ : (flags
+ & (MU_STREAM_READ |
+ MU_STREAM_WRITE |
+ MU_STREAM_RDWR));
filter->type = type;
status = mu_property_create (&(filter->property), filter);
@@ -249,8 +253,8 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
}
}
- mu_stream_set_open (*pstream, filter_open, filter );
- mu_stream_set_close (*pstream, filter_close, filter );
+ mu_stream_set_open (*pstream, filter_open, filter);
+ mu_stream_set_close (*pstream, filter_close, filter);
mu_stream_set_read (*pstream, filter_read, filter);
mu_stream_set_readline (*pstream, filter_readline, filter);
mu_stream_set_write (*pstream, filter_write, filter);
diff --git a/mailbox/filter_iconv.c b/mailbox/filter_iconv.c
index c09d4631b..e47c5db25 100644
--- a/mailbox/filter_iconv.c
+++ b/mailbox/filter_iconv.c
@@ -114,6 +114,7 @@ _icvt_destroy (mu_stream_t stream)
s->buf = NULL;
if (s->cd != (iconv_t) -1)
iconv_close (s->cd);
+ free (s);
}
static int _icvt_read (mu_stream_t stream, char *optr, size_t osize,
diff --git a/mailbox/mutil.c b/mailbox/mutil.c
index 19dbcc1c8..70bce589e 100644
--- a/mailbox/mutil.c
+++ b/mailbox/mutil.c
@@ -1329,8 +1329,8 @@ mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
{
mu_stream_t cvt;
status = mu_filter_iconv_create (&cvt, filter, fromcode, tocode,
- MU_STREAM_NO_CLOSE,
- mu_default_fallback_mode);
+ MU_STREAM_NO_CLOSE,
+ mu_default_fallback_mode);
if (status == 0)
{
if (mu_stream_open (cvt))
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 489d0285d..6d8c651ea 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -699,7 +699,8 @@ eval_body (struct eval_env *env)
if (encoding)
{
int rc = mu_filter_create(&dstr, input, encoding,
- MU_FILTER_DECODE, MU_STREAM_READ);
+ MU_FILTER_DECODE,
+ MU_STREAM_READ | MU_STREAM_NO_CLOSE);
if (rc == 0)
input = dstr;
free (encoding);
diff --git a/mh/mhn.c b/mh/mhn.c
index f37d63d0d..b54d109ce 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -1122,8 +1122,9 @@ mhn_message_size (mu_message_t msg, size_t *psize)
mu_message_get_header (msg, &hdr);
_get_content_encoding (hdr, &encoding);
- rc = mu_filter_create(&dstr, bstr, encoding,
- MU_FILTER_DECODE, MU_STREAM_READ);
+ rc = mu_filter_create (&dstr, bstr, encoding,
+ MU_FILTER_DECODE,
+ MU_STREAM_READ | MU_STREAM_NO_CLOSE);
free (encoding);
if (rc == 0)
{
@@ -1272,8 +1273,8 @@ show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t ou
return 0;
}
mu_body_get_stream (body, &bstr);
- rc = mu_filter_create(&dstr, bstr, encoding,
- MU_FILTER_DECODE, MU_STREAM_READ);
+ rc = mu_filter_create (&dstr, bstr, encoding,
+ MU_FILTER_DECODE, MU_STREAM_READ | MU_STREAM_NO_CLOSE);
if (rc == 0)
bstr = dstr;
cat_message (out, bstr);
@@ -2052,10 +2053,12 @@ finish_text_msg (struct compose_env *env, mu_message_t *msg, int ascii)
mu_message_get_body (*msg, &body);
mu_body_get_stream (body, &input);
rc = mu_filter_create (&fstr, input, "quoted-printable",
- MU_FILTER_ENCODE, MU_STREAM_READ);
+ MU_FILTER_ENCODE,
+ MU_STREAM_READ | MU_STREAM_NO_CLOSE);
if (rc == 0)
{
cat_message (output, fstr);
+ mu_stream_destroy (&fstr, NULL);
mu_message_unref (*msg);
*msg = newmsg;
}

Return to:

Send suggestions and report system problems to the System administrator.