Commit 18944214 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Prevent leakage of SerialIoHandler by canceling I/O

In r626961 and r643767 we removed the CancelRead() and CancelWrite()
calls from ~SerialConnection() with the assumption that since the
SerialPortPtr was being closed it would cancel I/O in the process of
closing the OS-level file handle. The problem is that SerialIoHandler
explicitly retains a self-reference when submitting a read or write
operation and until those are completed (or canceled) the object won't
be destroyed and the OS-level file handle closed.

SerialConnection solved this problem by explicitly canceling the I/O in
its destructor and this patch moves that logic to ~SerialPortImpl().

A better long-term fix is to remove the self-references and make
SerialIoHandler uniquely owned by SerialPortImpl but that requires other
refactoring work.

Bug: 964683
Change-Id: Ie5e59696df23c48dc9e9224772c621db5438c1f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1707028
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678396}
parent 405f16bb
......@@ -46,7 +46,11 @@ SerialPortImpl::SerialPortImpl(
}
}
SerialPortImpl::~SerialPortImpl() = default;
SerialPortImpl::~SerialPortImpl() {
// Cancel I/O operations so that |io_handler_| drops its self-reference.
io_handler_->CancelRead(mojom::SerialReceiveError::DISCONNECTED);
io_handler_->CancelWrite(mojom::SerialSendError::DISCONNECTED);
}
void SerialPortImpl::Open(mojom::SerialConnectionOptionsPtr options,
mojo::ScopedDataPipeConsumerHandle in_stream,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment