diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-04-14 18:23:42 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-04-14 18:23:42 +0300 |
commit | dbbf8dae0bdd56d108f8bfda7614b4a3b895eae2 (patch) | |
tree | 75e2168e73ebb642bde137dfac1092a9c0b6483b /mailbox | |
parent | 77b116b12786c1f9520e87868528494db61ce8af (diff) | |
download | mailutils-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.
Diffstat (limited to 'mailbox')
-rw-r--r-- | mailbox/attachment.c | 3 | ||||
-rw-r--r-- | mailbox/filter.c | 16 | ||||
-rw-r--r-- | mailbox/filter_iconv.c | 1 | ||||
-rw-r--r-- | mailbox/mutil.c | 4 |
4 files changed, 15 insertions, 9 deletions
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)) |