From 2294a5ce693d01453bdb2424ac5d0238a24f235f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 29 Dec 2015 10:40:10 +0800 Subject: [PATCH] Leak FunctionTemplateHandle They are cached through the app's lifetime, and freeing them at the right time is complicate, so just leak them. --- atom/common/api/atom_api_v8_util.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/atom/common/api/atom_api_v8_util.cc b/atom/common/api/atom_api_v8_util.cc index 7b9490df6a8b..c86335adb15e 100644 --- a/atom/common/api/atom_api_v8_util.cc +++ b/atom/common/api/atom_api_v8_util.cc @@ -13,10 +13,21 @@ namespace { -using FunctionTemplateHandle = - v8::CopyablePersistentTraits::CopyablePersistent; +// A Persistent that can be copied and will not free itself. +template +struct LeakedPersistentTraits { + typedef v8::Persistent > LeakedPersistent; + static const bool kResetInDestructor = false; + template + static V8_INLINE void Copy(const v8::Persistent& source, + LeakedPersistent* dest) { + // do nothing, just allow copy + } +}; // The handles are leaked on purpose. +using FunctionTemplateHandle = + LeakedPersistentTraits::LeakedPersistent; std::map function_templates_; v8::Local CreateObjectWithName(v8::Isolate* isolate,