]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add i_stream_free_buffer() to free i_stream_*alloc()ed memory
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 26 Oct 2017 13:24:50 +0000 (16:24 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 1 Nov 2017 11:45:51 +0000 (13:45 +0200)
src/lib/istream-private.h
src/lib/istream.c

index 6e86080854772c3a0389f4db6f5ed6ed4ee3af11..3fc8379dc25020bd4aa71ba149bf43714dcdd7a5 100644 (file)
@@ -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);
index 9665cbc3f7dd0c5cb8a4c2e5c727d504aadcd0a8..0c6a6129c148296f317c040f8081c63da3dce140 100644 (file)
@@ -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;