From: Timo Sirainen Date: Tue, 1 Mar 2016 14:07:53 +0000 (+0200) Subject: lib: Fixed memory leak io_add_istream()+io_remove() when the stream didn't have fd. X-Git-Tag: 2.2.22.rc1~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ba6ab5cf21a912c3a1b58dbf256b3c1dce6700b;p=thirdparty%2Fdovecot%2Fcore.git lib: Fixed memory leak io_add_istream()+io_remove() when the stream didn't have fd. --- diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index f485acf13f..eab5624d21 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -138,17 +138,22 @@ static void io_remove_full(struct io **_io, bool closed) struct io_file *io_file = (struct io_file *)io; struct istream *istream = io_file->istream; + if (istream != NULL) { + /* remove io before it's freed */ + i_stream_unset_io(istream, io); + } + io_file_unlink(io_file); if (io_file->fd != -1) io_loop_handle_remove(io_file, closed); + else + i_free(io); /* remove io from the ioloop before unreferencing the istream, because a destroyed istream may automatically close the fd. */ - if (istream != NULL) { - i_stream_unset_io(istream, io); + if (istream != NULL) i_stream_unref(&istream); - } } }