diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-06-15 17:00:51 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-06-15 17:27:15 +0300 |
commit | 45d54031f4e3f94d121b349b63f06c74ea1383d7 (patch) | |
tree | 005bb137a164a75e4db1d8f9b6fb7b2794988373 /include | |
parent | db3f8b9a2f1bb40a4b08e20e435f300fcfeb8928 (diff) | |
download | mailutils-45d54031f4e3f94d121b349b63f06c74ea1383d7.tar.gz mailutils-45d54031f4e3f94d121b349b63f06c74ea1383d7.tar.bz2 |
Fix long-standing memory leak in body.c
* include/mailutils/body.h (mu_body_ref, mu_body_unref): New functions.
* include/mailutils/sys/body.h (_mu_body): New member ref_count.
* libmailutils/mailbox/body.c: Keep body and body stream objects alive
for as long as their reference counters are not zero.
Rewrite transport stream code.
* libmailutils/tests/modmesg.c: Use MU_ASSERT.
Diffstat (limited to 'include')
-rw-r--r-- | include/mailutils/body.h | 2 | ||||
-rw-r--r-- | include/mailutils/sys/body.h | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/include/mailutils/body.h b/include/mailutils/body.h index 8e2e1d067..928dc6fec 100644 --- a/include/mailutils/body.h +++ b/include/mailutils/body.h @@ -42,6 +42,8 @@ extern int mu_body_set_size (mu_body_t, extern int mu_body_lines (mu_body_t, size_t *); extern int mu_body_set_lines (mu_body_t, int (*_lines) (mu_body_t, size_t*), void *owner); +extern void mu_body_ref (mu_body_t body); +extern void mu_body_unref (mu_body_t body); #ifdef __cplusplus } diff --git a/include/mailutils/sys/body.h b/include/mailutils/sys/body.h index eee709c19..8cd67d9ac 100644 --- a/include/mailutils/sys/body.h +++ b/include/mailutils/sys/body.h @@ -30,10 +30,10 @@ extern "C" { struct _mu_body { - void *owner; - mu_stream_t stream; - mu_stream_t rawstream; - mu_stream_t fstream; + int ref_count; /* Reference counter */ + void *owner; /* Owner object pointer */ + mu_stream_t data_stream; /* Body content stream */ + mu_stream_t temp_stream; /* RW temporary stream (for writing ro the body) */ int flags; int (*_size) (mu_body_t, size_t*); |