Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: fpdfsdk/fpdfview.cpp

Issue 2543833002: Protect against unexpected library create/destroy (Closed)
Patch Set: Add unittest Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/cpdf_modulemgr.h ('k') | fpdfsdk/fpdfview_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fpdfview.cpp
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 1c27b6c69b49c6188f5f26e57dc218bff4f3d366..633cbe879e1274a6a16c0af93b1afb034e3d4576 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -50,6 +50,9 @@
namespace {
+// Also indicates whether library is currently initialized.
+CCodec_ModuleMgr* g_pCodecModule = nullptr;
+
void RenderPageImpl(CPDF_PageRenderContext* pContext,
CPDF_Page* pPage,
const CFX_Matrix& matrix,
@@ -295,18 +298,20 @@ FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy) {
}
}
-CCodec_ModuleMgr* g_pCodecModule = nullptr;
-
DLLEXPORT void STDCALL FPDF_InitLibrary() {
FPDF_InitLibraryWithConfig(nullptr);
}
DLLEXPORT void STDCALL
FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) {
+ if (g_pCodecModule)
+ return;
+
g_pCodecModule = new CCodec_ModuleMgr();
CFX_GEModule* pModule = CFX_GEModule::Get();
pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr, g_pCodecModule);
+
CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get();
pModuleMgr->SetCodecModule(g_pCodecModule);
pModuleMgr->InitPageModule();
@@ -324,6 +329,9 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) {
}
DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
+ if (!g_pCodecModule)
+ return;
+
#ifdef PDF_ENABLE_XFA
BC_Library_Destory();
FXJSE_Finalize();
« no previous file with comments | « core/fpdfapi/cpdf_modulemgr.h ('k') | fpdfsdk/fpdfview_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698