diff options
author | weili <weili@chromium.org> | 2016-09-21 10:19:50 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-21 10:19:50 -0700 |
commit | 54be7be992f1cde40b9d5c0e55a119c6cc4e4e02 (patch) | |
tree | f5b2926ecf00cba53a9becb0db08b00e64c55ff5 /fxjs/cfxjse_runtimedata.cpp | |
parent | 5819e4f334521cb1599f3d5f1f28df40528727ba (diff) | |
download | pdfium-54be7be992f1cde40b9d5c0e55a119c6cc4e4e02.tar.xz |
Fix leaks related to the usage of JSE runtime data
Per isolate runtime data should be deleted when the associated
isolate's destructed.
Also, the internal of per isolate runtime data is obscure to the JS
engine. So XFA or this class itself has to be in charge of the memory
management. Use smart pointer for it so that the resource
could be released properly.
BUG=pdfium:242
Review-Url: https://codereview.chromium.org/2354923003
Diffstat (limited to 'fxjs/cfxjse_runtimedata.cpp')
-rw-r--r-- | fxjs/cfxjse_runtimedata.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/fxjs/cfxjse_runtimedata.cpp b/fxjs/cfxjse_runtimedata.cpp index 2c9379526e..021fb1dbe4 100644 --- a/fxjs/cfxjse_runtimedata.cpp +++ b/fxjs/cfxjse_runtimedata.cpp @@ -20,10 +20,8 @@ class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { }; void Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) { - if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) { - delete pData->m_pFXJSERuntimeData; - pData->m_pFXJSERuntimeData = nullptr; - } + if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) + delete pData; if (bOwned) pIsolate->Dispose(); } @@ -77,8 +75,10 @@ CFXJSE_RuntimeData::CFXJSE_RuntimeData(v8::Isolate* pIsolate) CFXJSE_RuntimeData::~CFXJSE_RuntimeData() {} -CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { - CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate); +std::unique_ptr<CFXJSE_RuntimeData> CFXJSE_RuntimeData::Create( + v8::Isolate* pIsolate) { + std::unique_ptr<CFXJSE_RuntimeData> pRuntimeData( + new CFXJSE_RuntimeData(pIsolate)); CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); v8::Local<v8::FunctionTemplate> hFuncTemplate = v8::FunctionTemplate::New(pIsolate); @@ -101,7 +101,7 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); if (!pData->m_pFXJSERuntimeData) pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate); - return pData->m_pFXJSERuntimeData; + return pData->m_pFXJSERuntimeData.get(); } CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr; |