From: Cheng Zhao Date: Mon, 29 Jul 2013 11:14:35 +0000 (+0800) Subject: Guard against double erasing an object, fixes #44. X-Git-Tag: v0.1.8~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=e9953834015d1801e87bda1fd331e7f7c1830986;p=electron.git Guard against double erasing an object, fixes #44. --- diff --git a/common/api/atom_api_id_weak_map.cc b/common/api/atom_api_id_weak_map.cc index 6fb868b7..601ac277 100644 --- a/common/api/atom_api_id_weak_map.cc +++ b/common/api/atom_api_id_weak_map.cc @@ -5,6 +5,8 @@ #include "common/api/atom_api_id_weak_map.h" +#include "base/logging.h" + namespace atom { namespace api { @@ -26,6 +28,11 @@ bool IDWeakMap::Has(int key) const { } void IDWeakMap::Erase(v8::Isolate* isolate, int key) { + if (!Has(key)) { + LOG(WARNING) << "Object with key " << key << " is being GCed for twice."; + return; + } + v8::Persistent value = map_[key]; value.ClearWeak(isolate); value.Dispose(isolate); @@ -47,6 +54,7 @@ void IDWeakMap::WeakCallback(v8::Isolate* isolate, IDWeakMap* obj = static_cast(data); int key = value->ToObject()->GetHiddenValue( v8::String::New("IDWeakMapKey"))->IntegerValue(); + obj->Erase(isolate, key); }