From 8f16b69981730911aa6185451e4899137cc4fca2 Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Tue, 27 Oct 2015 09:34:49 -0700 Subject: Merge to XFA: Fix memory leak in FXJS_ReleaseRuntime. Should fix a bunch of JS related memory leaks reported by LSan/DrMemory. Clean merge. TBR=tsepez@chromium.org BUG=pdfium:242 Review URL: https://codereview.chromium.org/1417973009 . (cherry picked from commit fbbb3c3de517309b6808d7a8f4c441aa0abf7065) Review URL: https://codereview.chromium.org/1406053006 . --- fpdfsdk/src/jsapi/fxjs_v8.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 1f8c5728b0..dde32ce784 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -340,9 +340,15 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); for (int i = 0; i < maxID; ++i) { CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); - if (!pObjDef->m_StaticObj.IsEmpty()) { - v8::Local pObj = - v8::Local::New(pIsolate, pObjDef->m_StaticObj); + v8::Local pObj; + if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { + pObj = + context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); + } else if (!pObjDef->m_StaticObj.IsEmpty()) { + pObj = v8::Local::New(pIsolate, pObjDef->m_StaticObj); + } + + if (!pObj.IsEmpty()) { if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(pObj); FXJS_FreePrivate(pObj); -- cgit v1.2.3