diff options
author | Oliver Chang <ochang@chromium.org> | 2015-10-27 09:21:32 -0700 |
---|---|---|
committer | Oliver Chang <ochang@chromium.org> | 2015-10-27 09:21:32 -0700 |
commit | fbbb3c3de517309b6808d7a8f4c441aa0abf7065 (patch) | |
tree | 9bc3f7be43041e909eb1be32b119dd0291657071 | |
parent | 4ef782ab57979add3e3910d6bcfde6ef59f65724 (diff) | |
download | pdfium-fbbb3c3de517309b6808d7a8f4c441aa0abf7065.tar.xz |
Fix memory leak in FXJS_ReleaseRuntime.
Should fix a bunch of JS related memory leaks reported by LSan/DrMemory.
R=jochen@chromium.org, thestig@chromium.org, tsepez@chromium.org
BUG=pdfium:242
Review URL: https://codereview.chromium.org/1417973009 .
-rw-r--r-- | fpdfsdk/src/jsapi/fxjs_v8.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 8a54475910..2fb3e13064 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -335,9 +335,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<v8::Object> pObj = - v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); + v8::Local<v8::Object> pObj; + if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { + pObj = + context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); + } else if (!pObjDef->m_StaticObj.IsEmpty()) { + pObj = v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); + } + + if (!pObj.IsEmpty()) { if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(pObj); FXJS_FreePrivate(pObj); |