Commit 9bf2d6f2 authored by Fred Ranking's avatar Fred Ranking Committed by Commit Bot

Fix FD leak in mojo::DataPipeProducer

data_source_ should be guaranteed to be release after
DataPipeProducer::Cancel() triggered,
This ensures that DataPipeProducer destruction eventually leads to
teardown of the corresponding SequenceState object.

Bug: 1095883
Change-Id: Ibf1d5787a57ae5da9eaa24e25e1e72c1a3a9907c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2245987
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#780053}
parent c11c1617
...@@ -311,6 +311,7 @@ Francois Marier <francois@brave.com> ...@@ -311,6 +311,7 @@ Francois Marier <francois@brave.com>
Francois Rauch <leopardb@gmail.com> Francois Rauch <leopardb@gmail.com>
Frankie Dintino <fdintino@theatlantic.com> Frankie Dintino <fdintino@theatlantic.com>
Franklin Ta <fta2012@gmail.com> Franklin Ta <fta2012@gmail.com>
Fred Ranking <luliang14@huawei.com>
Frédéric Jacob <frederic.jacob.78@gmail.com> Frédéric Jacob <frederic.jacob.78@gmail.com>
Frédéric Wang <fred.wang@free.fr> Frédéric Wang <fred.wang@free.fr>
Fu Junwei <junwei.fu@intel.com> Fu Junwei <junwei.fu@intel.com>
......
...@@ -53,6 +53,8 @@ class DataPipeProducer::SequenceState ...@@ -53,6 +53,8 @@ class DataPipeProducer::SequenceState
void Cancel() { void Cancel() {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
is_cancelled_ = true; is_cancelled_ = true;
owning_task_runner()->PostTask(
FROM_HERE, base::BindOnce(&SequenceState::CancelOnSequence, this));
} }
void Start(std::unique_ptr<DataSource> data_source) { void Start(std::unique_ptr<DataSource> data_source) {
...@@ -151,6 +153,13 @@ class DataPipeProducer::SequenceState ...@@ -151,6 +153,13 @@ class DataPipeProducer::SequenceState
std::move(producer_handle_), result)); std::move(producer_handle_), result));
} }
void CancelOnSequence() {
if (!data_source_)
return;
data_source_->Abort();
Finish(MOJO_RESULT_CANCELLED);
}
const scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; const scoped_refptr<base::SequencedTaskRunner> callback_task_runner_;
// State which is effectively owned and used only on the file sequence. // State which is effectively owned and used only on the file sequence.
......
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