fix: dangling raw_ptr in OSRWHV destructor (#41088)

`delegated_frame_host_` holds a pointer to `delegated_frame_host_client_`.
Since `delegated_frame_host_client_` was being destroyed first, that
pointer was dangling in the OSRWHV destructor.

Also, make these two unique_ptr fields `const` since they point to the
same objects for the lifespan of the OSRWHV.
This commit is contained in:
Charles Kerr 2024-01-24 19:15:32 -06:00 committed by GitHub
parent 3e6a038af7
commit 921da723b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 11 deletions

View file

@ -187,6 +187,12 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
frame_rate_(frame_rate),
size_(initial_size),
painting_(painting),
delegated_frame_host_client_{
std::make_unique<ElectronDelegatedFrameHostClient>(this)},
delegated_frame_host_{std::make_unique<content::DelegatedFrameHost>(
AllocateFrameSinkId(),
delegated_frame_host_client_.get(),
true /* should_register_frame_sink_id */)},
cursor_manager_(std::make_unique<content::CursorManager>(this)),
mouse_wheel_phase_handler_(this),
backing_(std::make_unique<SkBitmap>()) {
@ -205,12 +211,6 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
compositor_allocator_.GenerateId();
compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();
delegated_frame_host_client_ =
std::make_unique<ElectronDelegatedFrameHostClient>(this);
delegated_frame_host_ = std::make_unique<content::DelegatedFrameHost>(
AllocateFrameSinkId(), delegated_frame_host_client_.get(),
true /* should_register_frame_sink_id */);
root_layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);
bool opaque = SkColorGetA(background_color_) == SK_AlphaOPAQUE;
@ -247,7 +247,6 @@ OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
content::DelegatedFrameHost::HiddenCause::kOther);
delegated_frame_host_->DetachFromCompositor();
delegated_frame_host_.reset();
compositor_.reset();
root_layer_.reset();
}