Commit 78ae3efd authored by Kristian Høgsberg's avatar Kristian Høgsberg

2006-05-19 Kristian Høgsberg <krh@redhat.com>

	Memory leak patch from Carlos Garcia Campos (#6947).

	* glib/poppler-action.cc:
	* glib/poppler-document.cc:
	* glib/poppler-page.cc:
	* poppler/CairoFontEngine.cc:
	* poppler/CairoFontEngine.h:
	* poppler/CairoOutputDev.cc:
	* poppler/CairoOutputDev.h:
	* poppler/Gfx.cc:
	* poppler/TextOutputDev.cc:  Fix various memory leaks.
parent 354c1926
2006-05-19 Kristian Høgsberg <krh@redhat.com>
Memory leak patch from Carlos Garcia Campos (#6947).
* glib/poppler-action.cc:
* glib/poppler-document.cc:
* glib/poppler-page.cc:
* poppler/CairoFontEngine.cc:
* poppler/CairoFontEngine.h:
* poppler/CairoOutputDev.cc:
* poppler/CairoOutputDev.h:
* poppler/Gfx.cc:
* poppler/TextOutputDev.cc: Fix various memory leaks.
2006-05-19 Albert Astals Cid <aacid@kde.org>
* qt4/src/poppler-link.cc: Patch by Pino Toscano, ensure the
......
......@@ -244,6 +244,7 @@ static PopplerDest *
dest_new_named (UGooString *named_dest)
{
PopplerDest *dest;
gchar *name;
dest = g_new0 (PopplerDest, 1);
......@@ -253,7 +254,9 @@ dest_new_named (UGooString *named_dest)
}
dest->type = POPPLER_DEST_NAMED;
dest->named_dest = g_strdup (named_dest->getCString ());
name = named_dest->getCString ();
dest->named_dest = g_strdup (name);
delete[] name;
return dest;
}
......@@ -317,10 +320,10 @@ build_launch (PopplerAction *action,
LinkLaunch *link)
{
if (link->getFileName()) {
action->launch.file_name = link->getFileName()->getCString ();
action->launch.file_name = g_strdup (link->getFileName()->getCString ());
}
if (link->getParams()) {
action->launch.params = link->getParams()->getCString ();
action->launch.params = g_strdup (link->getParams()->getCString ());
}
}
......
......@@ -411,7 +411,7 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
int year, mon, day, hour, min, sec;
int scanned_items;
struct tm *time;
gchar *date_string;
gchar *date_string, *ds;
GTime result;
if (!info_dict->lookup ((gchar *)key, &obj)->isString ()) {
......@@ -428,7 +428,8 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
} else {
date_string = g_strndup (goo_value->getCString (), goo_value->getLength ());
}
ds = date_string;
/* See PDF Reference 1.3, Section 3.8.2 for PDF Date representation */
if (date_string [0] == 'D' && date_string [1] == ':')
......@@ -438,9 +439,12 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
scanned_items = sscanf (date_string, "%4d%2d%2d%2d%2d%2d",
&year, &mon, &day, &hour, &min, &sec);
if (scanned_items != 6)
if (scanned_items != 6) {
obj.free ();
g_free (ds);
return;
}
/* Workaround for y2k bug in Distiller 3, hoping that it won't
* be used after y2.2k */
if (year < 1930 && strlen (date_string) > 14) {
......@@ -448,9 +452,12 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
scanned_items = sscanf (date_string, "%2d%3d%2d%2d%2d%2d%2d",
&century, &years_since_1900, &mon, &day, &hour, &min, &sec);
if (scanned_items != 7)
if (scanned_items != 7) {
obj.free ();
g_free (ds);
return;
}
year = century * 100 + years_since_1900;
}
......@@ -468,12 +475,15 @@ info_dict_get_date (Dict *info_dict, const gchar *key, GValue *value)
/* compute tm_wday and tm_yday and check date */
if (mktime (time) == (time_t) - 1) {
obj.free ();
g_free (ds);
return;
} else {
result = mktime (time);
}
obj.free ();
g_free (ds);
g_value_set_int (value, result);
}
......@@ -540,6 +550,7 @@ poppler_document_get_property (GObject *object,
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_string (obj.getDict(), "Title", value);
obj.free ();
break;
case PROP_FORMAT:
str = g_strndup("PDF-", 15); /* allocates 16 chars, pads with \0s */
......@@ -551,36 +562,43 @@ poppler_document_get_property (GObject *object,
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_string (obj.getDict(), "Author", value);
obj.free ();
break;
case PROP_SUBJECT:
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_string (obj.getDict(), "Subject", value);
obj.free ();
break;
case PROP_KEYWORDS:
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_string (obj.getDict(), "Keywords", value);
obj.free ();
break;
case PROP_CREATOR:
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_string (obj.getDict(), "Creator", value);
obj.free ();
break;
case PROP_PRODUCER:
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_string (obj.getDict(), "Producer", value);
obj.free ();
break;
case PROP_CREATION_DATE:
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_date (obj.getDict(), "CreationDate", value);
obj.free ();
break;
case PROP_MOD_DATE:
document->doc->getDocInfo (&obj);
if (obj.isDict ())
info_dict_get_date (obj.getDict(), "ModDate", value);
obj.free ();
break;
case PROP_LINEARIZED:
if (document->doc->isLinearized ()) {
......@@ -1017,7 +1035,6 @@ poppler_index_iter_free (PopplerIndexIter *iter)
return;
g_object_unref (iter->document);
// delete iter->items;
g_free (iter);
}
......
......@@ -860,6 +860,8 @@ poppler_page_get_link_mapping (PopplerPage *page)
map_list = g_list_prepend (map_list, mapping);
}
delete links;
return map_list;
}
......
This diff is collapsed.
......@@ -18,19 +18,26 @@
class CairoFont {
public:
CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs);
~CairoFont();
static CairoFont *create(GfxFont *gfxFont, XRef *xref,
FT_Library lib, GBool useCIDs);
CairoFont *reference() { refcount++; return this; }
void unreference() { if (--refcount == 0) delete this; }
GBool matches(Ref &other);
cairo_font_face_t *getFontFace(void);
unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
private:
protected:
CairoFont(GfxFont *gfxFont, XRef *xref);
virtual ~CairoFont();
Ref ref;
XRef *xref;
cairo_font_face_t *cairo_font_face;
FT_Face face;
Gushort *codeToGID;
int codeToGIDLen;
int refcount;
};
//------------------------------------------------------------------------
......
......@@ -258,9 +258,6 @@ void CairoOutputDev::updateFont(GfxState *state) {
needFontUpdate = gFalse;
if (state->getFont()->getType() == fontType3)
return;
currentFont = fontEngine->getFont (state->getFont(), xref);
state->getFontTransMat(&m11, &m12, &m21, &m22);
......@@ -448,7 +445,7 @@ void CairoOutputDev::type3D0(GfxState *state, double wx, double wy) {
}
void CairoOutputDev::type3D1(GfxState *state, double wx, double wy,
double llx, double lly, double urx, double ury) {
double llx, double lly, double urx, double ury) {
}
void CairoOutputDev::endTextObject(GfxState *state) {
......
......@@ -52,7 +52,7 @@ public:
// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual GBool interpretType3Chars() { return gTrue; }
virtual GBool interpretType3Chars() { return gFalse; }
//----- initialization and control
......
......@@ -483,6 +483,7 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict,
// initialize
out = outA;
state = new GfxState(72, 72, box, 0, gFalse);
out->updateAll(state);
fontChanged = gFalse;
clip = clipNone;
ignoreUndef = 0;
......
......@@ -2375,6 +2375,8 @@ void TextPage::coalesce(GBool physLayout) {
//----- column assignment
// sort blocks into xy order for column assignment
if (blocks)
gfree (blocks);
blocks = (TextBlock **)gmallocn(nBlocks, sizeof(TextBlock *));
for (blk = blkList, i = 0; blk; blk = blk->next, ++i) {
blocks[i] = blk;
......@@ -2512,6 +2514,11 @@ void TextPage::coalesce(GBool physLayout) {
//~ this also needs to account for right-to-left column ordering
blkArray = (TextBlock **)gmallocn(nBlocks, sizeof(TextBlock *));
memcpy(blkArray, blocks, nBlocks * sizeof(TextBlock *));
while (flows) {
flow = flows;
flows = flows->next;
delete flow;
}
flows = lastFlow = NULL;
firstBlkIdx = 0;
nBlocksLeft = nBlocks;
......@@ -3375,6 +3382,8 @@ void TextSelectionPainter::visitWord (TextWord *word, int begin, int end,
word->charcode[i], 1, NULL, 0);
out->endString(state);
delete string;
}
void TextWord::visitSelection(TextSelectionVisitor *visitor,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment