mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: prevent destroyed view references from causing crashes (#25411)
Closes #21666. This PR is fixing crashes caused by referencing and attempting to modify previously destroyed views. Before, when a view was destroyed and then the contents were referenced for modification, the system would crash as undefined memory was accessed. This fix explicitly makes the pointer to the destroyed view's contents null, so that this will not happen.
This commit is contained in:
@@ -13,16 +13,26 @@ namespace electron {
|
||||
|
||||
NativeBrowserView::NativeBrowserView(
|
||||
InspectableWebContents* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents) {}
|
||||
: inspectable_web_contents_(inspectable_web_contents) {
|
||||
Observe(inspectable_web_contents_->GetWebContents());
|
||||
}
|
||||
|
||||
NativeBrowserView::~NativeBrowserView() = default;
|
||||
|
||||
InspectableWebContentsView* NativeBrowserView::GetInspectableWebContentsView() {
|
||||
if (!inspectable_web_contents_)
|
||||
return nullptr;
|
||||
return inspectable_web_contents_->GetView();
|
||||
}
|
||||
|
||||
content::WebContents* NativeBrowserView::GetWebContents() {
|
||||
if (!inspectable_web_contents_)
|
||||
return nullptr;
|
||||
return inspectable_web_contents_->GetWebContents();
|
||||
}
|
||||
|
||||
void NativeBrowserView::WebContentsDestroyed() {
|
||||
inspectable_web_contents_ = nullptr;
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
Reference in New Issue
Block a user