only in patch2: unchanged: --- poppler-0.5.1.orig/poppler/GfxFont.h +++ poppler-0.5.1/poppler/GfxFont.h @@ -115,6 +115,9 @@ GBool isOk() { return ok; } + void incRefCnt(); + void decRefCnt(); + // Get font tag. GooString *getTag() { return tag; } @@ -215,6 +218,7 @@ double missingWidth; // "default" width double ascent; // max height above baseline double descent; // max depth below baseline + int refCnt; GBool ok; }; only in patch2: unchanged: --- poppler-0.5.1.orig/poppler/Gfx.cc +++ poppler-0.5.1/poppler/Gfx.cc @@ -2523,6 +2523,8 @@ args[1].getNum()); fflush(stdout); } + + font->incRefCnt(); state->setFont(font, args[1].getNum()); fontChanged = gTrue; } only in patch2: unchanged: --- poppler-0.5.1.orig/poppler/GfxFont.cc +++ poppler-0.5.1/poppler/GfxFont.cc @@ -148,6 +148,7 @@ family = NULL; stretch = StretchNotDefined; weight = WeightNotDefined; + refCnt = 1; } GfxFont::~GfxFont() { @@ -167,6 +168,15 @@ } } +void GfxFont::incRefCnt() { + refCnt++; +} + +void GfxFont::decRefCnt() { + if (--refCnt == 0) + delete this; +} + void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) { Object obj1, obj2, obj3, obj4; double t; @@ -457,6 +467,7 @@ Object obj1, obj2, obj3; int n, i, a, b, m; + refCnt = 1; type = typeA; ctu = NULL; @@ -1108,6 +1119,7 @@ int c1, c2; int excepsSize, i, j, k, n; + refCnt = 1; ascent = 0.95; descent = -0.35; fontBBox[0] = fontBBox[1] = fontBBox[2] = fontBBox[3] = 0; @@ -1620,7 +1632,7 @@ for (i = 0; i < numFonts; ++i) { if (fonts[i]) { - delete fonts[i]; + fonts[i]->decRefCnt(); } } gfree(fonts); only in patch2: unchanged: --- poppler-0.5.1.orig/poppler/GfxState.cc +++ poppler-0.5.1/poppler/GfxState.cc @@ -21,6 +21,7 @@ #include "Array.h" #include "Page.h" #include "GfxState.h" +#include "GfxFont.h" #include "UGooString.h" //------------------------------------------------------------------------ @@ -3849,6 +3850,9 @@ if (saved) { delete saved; } + if (font) { + font->decRefCnt(); + } } // Used for copy(); @@ -3870,6 +3874,9 @@ lineDash = (double *)gmallocn(lineDashLength, sizeof(double)); memcpy(lineDash, state->lineDash, lineDashLength * sizeof(double)); } + if (font) + font->incRefCnt(); + saved = NULL; } only in patch2: unchanged: --- poppler-0.5.1.orig/poppler/TextOutputDev.cc +++ poppler-0.5.1/poppler/TextOutputDev.cc @@ -3359,6 +3359,7 @@ state->setFillColor(glyph_color); out->updateFillColor(state); + word->font->gfxFont->incRefCnt(); state->setFont(word->font->gfxFont, word->fontSize); out->updateFont(state); only in patch2: unchanged: --- poppler-0.5.1.orig/glib/poppler-page.cc +++ poppler-0.5.1/glib/poppler-page.cc @@ -277,7 +277,7 @@ dst += pixbuf_n_channels; } } - delete pixel; + delete [] pixel; } #endif