Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
fix memory leak, error message and possible crash in remote object re…
Browse files Browse the repository at this point in the history
…gistry

auditors: @bbondy
related #6832
  • Loading branch information
bridiver committed Aug 16, 2016
1 parent 19796b9 commit e12f817
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions atom/common/api/remote_object_freer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ void RemoteObjectFreer::BindTo(
RemoteObjectFreer::RemoteObjectFreer(
v8::Isolate* isolate, v8::Local<v8::Object> target, int object_id)
: ObjectLifeMonitor(isolate, target),
object_id_(object_id) {
object_id_(object_id),
routing_id_(MSG_ROUTING_NONE) {
content::RenderView* render_view = GetCurrentRenderView();
if (render_view) {
routing_id_ = render_view->GetRoutingID();
}
}

RemoteObjectFreer::~RemoteObjectFreer() {
}

void RemoteObjectFreer::RunDestructor() {
content::RenderView* render_view = GetCurrentRenderView();
content::RenderView* render_view =
content::RenderView::FromRoutingID(routing_id_);
if (!render_view)
return;

Expand Down
1 change: 1 addition & 0 deletions atom/common/api/remote_object_freer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class RemoteObjectFreer : public ObjectLifeMonitor {

private:
int object_id_;
int routing_id_;

DISALLOW_COPY_AND_ASSIGN(RemoteObjectFreer);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/objects-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ObjectsRegistry {

// Get an object according to its ID.
get (id) {
return this.storage[id].object
return this.storage[id] && this.storage[id].object
}

// Dereference an object according to its ID.
Expand Down
4 changes: 4 additions & 0 deletions lib/browser/rpc-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ ipcMain.on('ELECTRON_BROWSER_MEMBER_CALL', function (event, id, method, args) {
try {
args = unwrapArgs(event.sender, args)
let obj = objectsRegistry.get(id)
if (!obj) {
console.error(`Calling method ${method} with ${args} on WebContents with unknown ID ${id}`)
return
}
callFunction(event, obj[method], obj, args)
} catch (error) {
event.returnValue = exceptionToMeta(error)
Expand Down

0 comments on commit e12f817

Please sign in to comment.