From: Timo Sirainen Date: Thu, 26 Oct 2017 13:24:50 +0000 (+0300) Subject: lib: Add i_stream_free_buffer() to free i_stream_*alloc()ed memory X-Git-Tag: 2.3.0.rc1~651 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=785ee8becdb11e41abaaf64c28eb3923215d1f27;p=thirdparty%2Fdovecot%2Fcore.git lib: Add i_stream_free_buffer() to free i_stream_*alloc()ed memory --- diff --git a/src/lib/istream-private.h b/src/lib/istream-private.h index 6e86080854..3fc8379dc2 100644 --- a/src/lib/istream-private.h +++ b/src/lib/istream-private.h @@ -68,6 +68,8 @@ bool ATTR_NOWARN_UNUSED_RESULT i_stream_try_alloc(struct istream_private *stream, size_t wanted_size, size_t *size_r); void *i_stream_alloc(struct istream_private *stream, size_t size); +/* Free memory allocated by i_stream_*alloc() */ +void i_stream_free_buffer(struct istream_private *stream); ssize_t i_stream_read_copy_from_parent(struct istream *istream); void i_stream_default_seek_nonseekable(struct istream_private *stream, uoff_t v_offset, bool mark); diff --git a/src/lib/istream.c b/src/lib/istream.c index 9665cbc3f7..0c6a6129c1 100644 --- a/src/lib/istream.c +++ b/src/lib/istream.c @@ -274,6 +274,17 @@ ssize_t i_stream_read_copy_from_parent(struct istream *istream) return ret; } +void i_stream_free_buffer(struct istream_private *stream) +{ + if (stream->w_buffer != NULL) { + i_free_and_null(stream->w_buffer); + } else { + /* don't know how to free it */ + return; + } + stream->buffer_size = 0; +} + void i_stream_skip(struct istream *stream, uoff_t count) { struct istream_private *_stream = stream->real_stream;