summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-11-22 20:21:21 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-22 20:21:21 +0000
commita1c4205eff6c8a0bb6a6abf58bbec06cb0fe22c5 (patch)
tree9a5cf8db989cc3187970fcfacd0462255cf34a87
parenta27e55e1c8c04fa85e2132e98e92b42d1a084b1f (diff)
downloadpdfium-chromium/3276.tar.xz
Call FreeLibrary() in CGdiplusExt.chromium/3276
BUG=pdfium:939 Change-Id: I4204965bd8b81bea3c485fcb27adfa212cce4e69 Reviewed-on: https://pdfium-review.googlesource.com/19190 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp34
-rw-r--r--core/fxge/win32/win32_int.h12
2 files changed, 26 insertions, 20 deletions
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index 1a7e132c64..a8066fe4b1 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -112,6 +112,7 @@ enum {
FuncId_GdipDrawString,
FuncId_GdipSetPenTransform,
};
+
static LPCSTR g_GdipFuncNames[] = {
"GdipCreatePath2",
"GdipSetPenDashStyle",
@@ -192,6 +193,10 @@ static LPCSTR g_GdipFuncNames[] = {
"GdipDrawString",
"GdipSetPenTransform",
};
+static_assert(FX_ArraySize(g_GdipFuncNames) ==
+ static_cast<size_t>(FuncId_GdipSetPenTransform) + 1,
+ "g_GdipFuncNames has wrong size");
+
typedef GpStatus(WINGDIPAPI* FuncType_GdipCreatePath2)(GDIPCONST GpPointF*,
GDIPCONST BYTE*,
INT,
@@ -672,33 +677,32 @@ static void OutputImage(GpGraphics* pGraphics,
CallFunc(GdipDrawImagePointsI)(pGraphics, bitmap, destinationPoints, 3);
CallFunc(GdipDisposeImage)(bitmap);
}
-CGdiplusExt::CGdiplusExt() {
- m_hModule = nullptr;
- m_GdiModule = nullptr;
- for (size_t i = 0; i < sizeof g_GdipFuncNames / sizeof(LPCSTR); i++) {
- m_Functions[i] = nullptr;
- }
- m_pGdiAddFontMemResourceEx = nullptr;
- m_pGdiRemoveFontMemResourseEx = nullptr;
+
+CGdiplusExt::CGdiplusExt() {}
+
+CGdiplusExt::~CGdiplusExt() {
+ FreeLibrary(m_GdiModule);
+ FreeLibrary(m_hModule);
}
+
void CGdiplusExt::Load() {
- ByteString strPlusPath;
char buf[MAX_PATH];
GetSystemDirectoryA(buf, MAX_PATH);
- strPlusPath += buf;
- strPlusPath += "\\";
- strPlusPath += "GDIPLUS.DLL";
- m_hModule = LoadLibraryA(strPlusPath.c_str());
+ ByteString dllpath = buf;
+ dllpath += "\\GDIPLUS.DLL";
+ m_hModule = LoadLibraryA(dllpath.c_str());
if (!m_hModule)
return;
- for (size_t i = 0; i < sizeof g_GdipFuncNames / sizeof(LPCSTR); i++) {
+ m_Functions.resize(FX_ArraySize(g_GdipFuncNames));
+ for (size_t i = 0; i < FX_ArraySize(g_GdipFuncNames); ++i) {
m_Functions[i] = GetProcAddress(m_hModule, g_GdipFuncNames[i]);
if (!m_Functions[i]) {
m_hModule = nullptr;
return;
}
}
+
uintptr_t gdiplusToken;
GdiplusStartupInput gdiplusStartupInput;
((FuncType_GdiplusStartup)m_Functions[FuncId_GdiplusStartup])(
@@ -714,7 +718,7 @@ void CGdiplusExt::Load() {
reinterpret_cast<FuncType_GdiRemoveFontMemResourceEx>(
GetProcAddress(m_GdiModule, "RemoveFontMemResourceEx"));
}
-CGdiplusExt::~CGdiplusExt() {}
+
LPVOID CGdiplusExt::LoadMemFont(LPBYTE pData, uint32_t size) {
GpFontCollection* pCollection = nullptr;
CGdiplusExt& GdiplusExt =
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index c4559f4741..d4f2597033 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -10,6 +10,7 @@
#include <windows.h>
#include <memory>
+#include <vector>
#include "core/fxcrt/retain_ptr.h"
#include "core/fxge/cfx_pathdata.h"
@@ -32,6 +33,7 @@ class CGdiplusExt {
public:
CGdiplusExt();
~CGdiplusExt();
+
void Load();
bool IsAvailable() { return !!m_hModule; }
bool StretchBitMask(HDC hDC,
@@ -108,13 +110,13 @@ class CGdiplusExt {
bool GdiRemoveFontMemResourceEx(void* handle);
RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
- FARPROC m_Functions[100];
- FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx;
- FuncType_GdiRemoveFontMemResourceEx m_pGdiRemoveFontMemResourseEx;
+ std::vector<FARPROC> m_Functions;
+ FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx = nullptr;
+ FuncType_GdiRemoveFontMemResourceEx m_pGdiRemoveFontMemResourseEx = nullptr;
protected:
- HMODULE m_hModule;
- HMODULE m_GdiModule;
+ HMODULE m_hModule = nullptr;
+ HMODULE m_GdiModule = nullptr;
};
class CWin32Platform {