Fix memory leak in mu_stream_destroy
* libmailutils/stream/stream.c (mu_stream_destroy): Free buffer space. (mu_stream_set_buffer,mu_stream_getdelim): Use stdlib allocation functions instead of mu wrappers.
Showing
1 changed file
with
9 additions
and
3 deletions
... | @@ -260,6 +260,12 @@ mu_stream_destroy (mu_stream_t *pstream) | ... | @@ -260,6 +260,12 @@ mu_stream_destroy (mu_stream_t *pstream) |
260 | if (str && (str->ref_count == 0 || --str->ref_count == 0)) | 260 | if (str && (str->ref_count == 0 || --str->ref_count == 0)) |
261 | { | 261 | { |
262 | mu_stream_close (str); | 262 | mu_stream_close (str); |
263 | if (str->buftype != mu_buffer_none) | ||
264 | { | ||
265 | free (str->buffer); | ||
266 | str->buffer = NULL; | ||
267 | str->buftype = mu_buffer_none; | ||
268 | } | ||
263 | if (str->done) | 269 | if (str->done) |
264 | str->done (str); | 270 | str->done (str); |
265 | if (str->destroy) | 271 | if (str->destroy) |
... | @@ -553,7 +559,7 @@ mu_stream_set_buffer (mu_stream_t stream, enum mu_buffer_type type, | ... | @@ -553,7 +559,7 @@ mu_stream_set_buffer (mu_stream_t stream, enum mu_buffer_type type, |
553 | return 0; | 559 | return 0; |
554 | } | 560 | } |
555 | 561 | ||
556 | stream->buffer = mu_alloc (size); | 562 | stream->buffer = malloc (size); |
557 | if (stream->buffer == NULL) | 563 | if (stream->buffer == NULL) |
558 | { | 564 | { |
559 | stream->buftype = mu_buffer_none; | 565 | stream->buftype = mu_buffer_none; |
... | @@ -899,7 +905,7 @@ mu_stream_getdelim (mu_stream_t stream, char **pbuf, size_t *psize, | ... | @@ -899,7 +905,7 @@ mu_stream_getdelim (mu_stream_t stream, char **pbuf, size_t *psize, |
899 | { | 905 | { |
900 | char *new_lineptr; | 906 | char *new_lineptr; |
901 | n = 120; | 907 | n = 120; |
902 | new_lineptr = mu_realloc (lineptr, n); | 908 | new_lineptr = realloc (lineptr, n); |
903 | if (new_lineptr == NULL) | 909 | if (new_lineptr == NULL) |
904 | return ENOMEM; | 910 | return ENOMEM; |
905 | lineptr = new_lineptr; | 911 | lineptr = new_lineptr; |
... | @@ -925,7 +931,7 @@ mu_stream_getdelim (mu_stream_t stream, char **pbuf, size_t *psize, | ... | @@ -925,7 +931,7 @@ mu_stream_getdelim (mu_stream_t stream, char **pbuf, size_t *psize, |
925 | break; | 931 | break; |
926 | } | 932 | } |
927 | 933 | ||
928 | new_lineptr = mu_realloc (lineptr, needed); | 934 | new_lineptr = realloc (lineptr, needed); |
929 | if (new_lineptr == NULL) | 935 | if (new_lineptr == NULL) |
930 | { | 936 | { |
931 | rc = ENOMEM; | 937 | rc = ENOMEM; | ... | ... |
-
Please register or sign in to post a comment