]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Fixed memory leak io_add_istream()+io_remove() when the stream didn't have fd.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 1 Mar 2016 14:07:53 +0000 (16:07 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 1 Mar 2016 14:08:51 +0000 (16:08 +0200)
src/lib/ioloop.c

index f485acf13f01831c31372438d52af1033928d8a4..eab5624d21345b326595c897fa113f4a52b809d6 100644 (file)
@@ -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);
-               }
        }
 }