forked from electron/electron
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent destroyed view references from causing crashes (electron…
…#25411) Closes electron#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.
- Loading branch information
1 parent
6c3c9b5
commit 1d5eb77
Showing
5 changed files
with
90 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
spec-main/fixtures/crash-cases/api-browser-destroy/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { app, BrowserWindow, BrowserView } = require('electron'); | ||
const { expect } = require('chai'); | ||
|
||
function createWindow () { | ||
// Create the browser window. | ||
const mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
nodeIntegration: true | ||
} | ||
}); | ||
const view = new BrowserView(); | ||
mainWindow.addBrowserView(view); | ||
view.webContents.destroy(); | ||
view.setBounds({ x: 0, y: 0, width: 0, height: 0 }); | ||
const bounds = view.getBounds(); | ||
expect(bounds).to.deep.equal({ x: 0, y: 0, width: 0, height: 0 }); | ||
view.setBackgroundColor('#56cc5b10'); | ||
} | ||
|
||
app.on('ready', () => { | ||
createWindow(); | ||
setTimeout(() => app.quit()); | ||
}); |