Skip to content

Commit

Permalink
lib: Add i_stream_free_buffer() to free i_stream_*alloc()ed memory
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and Timo Sirainen committed Nov 1, 2017
1 parent 4c7d704 commit 785ee8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/istream-private.h
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/lib/istream.c
Expand Up @@ -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;
Expand Down

0 comments on commit 785ee8b

Please sign in to comment.