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

Unified Diff: core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp

Issue 477323002: Font is used after release in CPDF_TextStateData::~CPDF_TextStateData (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months 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
Index: core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
index 8053718c190fef0413ae94c8a1857a2a30f136ca..4227dcd62c4b7992ab7a31eb4853203900c1faa1 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp
@@ -285,6 +285,7 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, FX_FLOAT* pValue,
CPDF_TextStateData::CPDF_TextStateData()
{
m_pFont = NULL;
+ m_pDocument = NULL;
m_FontSize = 1.0f;
m_WordSpace = 0;
m_CharSpace = 0;
@@ -296,27 +297,35 @@ CPDF_TextStateData::CPDF_TextStateData()
}
CPDF_TextStateData::CPDF_TextStateData(const CPDF_TextStateData& src)
{
+ if (this == &src) {
+ return;
+ }
FXSYS_memcpy32(this, &src, sizeof(CPDF_TextStateData));
- if (m_pFont && m_pFont->m_pDocument) {
- m_pFont = m_pFont->m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE);
+ if (m_pDocument) {
Tom Sepez 2014/08/18 22:34:16 Are we sure that removing the m_pFont test is OK?
jun_fang 2014/08/18 22:59:31 At line 304, I will change it back as below: if (m
+ m_pFont = m_pDocument->GetPageData()->GetFont(m_pFont->GetFontDict(), FALSE);
}
}
CPDF_TextStateData::~CPDF_TextStateData()
{
- CPDF_Font* pFont = m_pFont;
- if (pFont && pFont->m_pDocument) {
- pFont->m_pDocument->GetPageData()->ReleaseFont(pFont->GetFontDict());
+ if (m_pDocument) {
Tom Sepez 2014/08/18 22:09:22 nit: this test could be (m_pDocument && m_pFont) s
+ CPDF_DocPageData *pPageData = m_pDocument->GetPageData();
+ if (pPageData && m_pFont && !pPageData->IsForceClear()) {
+ pPageData->ReleaseFont(m_pFont->GetFontDict());
+ }
}
}
void CPDF_TextState::SetFont(CPDF_Font* pFont)
{
- CPDF_Font*& pStateFont = GetModify()->m_pFont;
- CPDF_DocPageData* pDocPageData = NULL;
- if (pStateFont && pStateFont->m_pDocument) {
- pDocPageData = pStateFont->m_pDocument->GetPageData();
- pDocPageData->ReleaseFont(pStateFont->GetFontDict());
+ CPDF_TextStateData* pStateData = GetModify();
+ CPDF_Document* pDoc = pStateData ? pStateData->m_pDocument : NULL;
Tom Sepez 2014/08/18 22:09:22 nit: can move this inside the if (pStateData) test
+ if (pStateData) {
+ CPDF_DocPageData *pPageData = pDoc ? pDoc->GetPageData() : NULL;
+ if (pPageData && pStateData->m_pFont && !pPageData->IsForceClear()) {
+ pPageData->ReleaseFont(pStateData->m_pFont->GetFontDict());
+ }
+ pStateData->m_pDocument = pFont ? pFont->m_pDocument : NULL;
+ pStateData->m_pFont = pFont;
}
- pStateFont = pFont;
}
FX_FLOAT CPDF_TextState::GetFontSizeV() const
{

Powered by Google App Engine
This is Rietveld 408576698