Commit 0ab3b491 authored by Greg Thompson's avatar Greg Thompson Committed by Chromium LUCI CQ

Fix crash when running a FileDescriptorWatcher's callback.

Make a copy of the Controller's RepeatingClosure before running it in
case the Controller is deleted by the callback. This is a speculative
fix for a crash seen on macOS when running a Controller's callback.

R=fdoray@chromium.org

Bug: 1156603
Change-Id: Ib6049c9346f37071ae6a690fff3d6e8585b4a356
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598902
Auto-Submit: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839728}
parent d79324ba
...@@ -234,7 +234,11 @@ void FileDescriptorWatcher::Controller::RunCallback() { ...@@ -234,7 +234,11 @@ void FileDescriptorWatcher::Controller::RunCallback() {
WeakPtr<Controller> weak_this = weak_factory_.GetWeakPtr(); WeakPtr<Controller> weak_this = weak_factory_.GetWeakPtr();
callback_.Run(); // Run a copy of the callback in case this Controller is deleted by the
// callback. This would cause the callback itself to be deleted while it is
// being run.
RepeatingClosure callback_copy = callback_;
callback_copy.Run();
// If |this| wasn't deleted, re-enable the watch. // If |this| wasn't deleted, re-enable the watch.
if (weak_this) if (weak_this)
......
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