Keep track of MapFont/DeleteFont calls in SystemFontInfoWrapper.
Make sure code that calls out to this test-only font mapper have
balanced MapFont and DeleteFont calls.
Change-Id: Ib72ac71d65f1fe7bdb60e3efffe329d493704cc9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91951
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/testing/test_fonts.cpp b/testing/test_fonts.cpp
index 452946f..e76b5e4 100644
--- a/testing/test_fonts.cpp
+++ b/testing/test_fonts.cpp
@@ -4,6 +4,7 @@
#include "testing/test_fonts.h"
+#include <set>
#include <utility>
#include "core/fxge/cfx_fontmapper.h"
@@ -45,7 +46,7 @@
public:
explicit SystemFontInfoWrapper(std::unique_ptr<SystemFontInfoIface> impl)
: impl_(std::move(impl)) {}
- ~SystemFontInfoWrapper() = default;
+ ~SystemFontInfoWrapper() { CHECK(active_fonts_.empty()); }
bool EnumFontList(CFX_FontMapper* pMapper) override {
return impl_->EnumFontList(pMapper);
@@ -55,8 +56,13 @@
FX_Charset charset,
int pitch_family,
const ByteString& face) override {
- return impl_->MapFont(weight, bItalic, charset, pitch_family,
- RenameFontForTesting(face));
+ void* font = impl_->MapFont(weight, bItalic, charset, pitch_family,
+ RenameFontForTesting(face));
+ if (font) {
+ bool inserted = active_fonts_.insert(font).second;
+ CHECK(inserted);
+ }
+ return font;
}
void* GetFont(const ByteString& face) override {
return impl_->GetFont(RenameFontForTesting(face));
@@ -73,10 +79,14 @@
bool GetFontCharset(void* hFont, FX_Charset* charset) override {
return impl_->GetFontCharset(hFont, charset);
}
- void DeleteFont(void* hFont) override { impl_->DeleteFont(hFont); }
+ void DeleteFont(void* hFont) override {
+ CHECK(active_fonts_.erase(hFont));
+ impl_->DeleteFont(hFont);
+ }
private:
std::unique_ptr<SystemFontInfoIface> impl_;
+ std::set<void*> active_fonts_;
};
} // namespace