Index: ChangeLog =================================================================== RCS file: /cvs/poppler/poppler/ChangeLog,v retrieving revision 1.355 diff -u -u -r1.355 ChangeLog --- ChangeLog 5 May 2006 20:51:01 -0000 1.355 +++ ChangeLog 8 May 2006 16:55:30 -0000 @@ -1,3 +1,18 @@ +2006-05-08 Carlos Garcia Campos + + * glib/poppler-action.cc: + * glib/poppler-document.cc: + * glib/poppler-page.cc: + * poppler/Catalog.cc: + * poppler/GfxState.cc: + * poppler/GfxState.h: + * poppler/GlobalParams.cc: + * poppler/GlobalParams.h: + * poppler/PDFDoc.cc: + * poppler/TextOutputDev.cc: + + Fix several memory leaks. + 2006-05-05 Albert Astals Cid * poppler/Function.cc: quick fix for KDE bug #126760 Index: glib/poppler-action.cc =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-action.cc,v retrieving revision 1.7 diff -u -u -r1.7 poppler-action.cc --- glib/poppler-action.cc 16 Apr 2006 22:59:44 -0000 1.7 +++ glib/poppler-action.cc 8 May 2006 16:55:30 -0000 @@ -244,6 +244,7 @@ dest_new_named (UGooString *named_dest) { PopplerDest *dest; + gchar *name; dest = g_new0 (PopplerDest, 1); @@ -253,7 +254,9 @@ } 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 @@ 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 ()); } } Index: glib/poppler-document.cc =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-document.cc,v retrieving revision 1.34 diff -u -u -r1.34 poppler-document.cc --- glib/poppler-document.cc 16 Apr 2006 22:59:44 -0000 1.34 +++ glib/poppler-document.cc 8 May 2006 16:55:30 -0000 @@ -87,7 +87,9 @@ document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL); - if (!globalParams) { + if (globalParams) { + globalParams->incRefCnt(); + } else { globalParams = new GlobalParams("/etc/xpdfrc"); } @@ -178,6 +180,10 @@ delete document->output_dev; delete document->doc; + + if (globalParams) { + globalParams->decRefCnt(); + } } /** @@ -540,6 +546,7 @@ 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 +558,43 @@ 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 ()) { @@ -1013,11 +1027,12 @@ void poppler_index_iter_free (PopplerIndexIter *iter) { + OutlineItem *item; + if (iter == NULL) return; g_object_unref (iter->document); -// delete iter->items; g_free (iter); } Index: glib/poppler-page.cc =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-page.cc,v retrieving revision 1.47 diff -u -u -r1.47 poppler-page.cc --- glib/poppler-page.cc 2 May 2006 04:38:39 -0000 1.47 +++ glib/poppler-page.cc 8 May 2006 16:55:31 -0000 @@ -860,6 +860,8 @@ map_list = g_list_prepend (map_list, mapping); } + delete links; + return map_list; } Index: poppler/Catalog.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/Catalog.cc,v retrieving revision 1.14 diff -u -u -r1.14 Catalog.cc --- poppler/Catalog.cc 18 Jan 2006 22:32:13 -0000 1.14 +++ poppler/Catalog.cc 8 May 2006 16:55:31 -0000 @@ -510,6 +510,7 @@ GBool NameTree::lookup(UGooString *name, Object *obj) { Entry **entry; + char *cname; entry = (Entry **) bsearch(name, entries, length, sizeof(Entry *), Entry::cmp); @@ -517,7 +518,9 @@ (*entry)->value.fetch(xref, obj); return gTrue; } else { - printf("failed to look up %s\n", name->getCString()); + cname = name->getCString(); + printf("failed to look up %s\n", cname); + delete[] cname; obj->initNull(); return gFalse; } Index: poppler/GfxState.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/GfxState.cc,v retrieving revision 1.11 diff -u -u -r1.11 GfxState.cc --- poppler/GfxState.cc 2 May 2006 04:38:39 -0000 1.11 +++ poppler/GfxState.cc 8 May 2006 16:55:31 -0000 @@ -3876,7 +3876,6 @@ } if (font) font->incRefCnt(); - saved = NULL; } @@ -4046,6 +4045,14 @@ strokePattern = pattern; } +void GfxState::setFont(GfxFont *fontA, double fontSizeA) { + if (font) + font->decRefCnt(); + + font = fontA; + fontSize = fontSizeA; +} + void GfxState::setLineDash(double *dash, int length, double start) { if (lineDash) gfree(lineDash); Index: poppler/GfxState.h =================================================================== RCS file: /cvs/poppler/poppler/poppler/GfxState.h,v retrieving revision 1.5 diff -u -u -r1.5 GfxState.h --- poppler/GfxState.h 18 Feb 2006 20:17:00 -0000 1.5 +++ poppler/GfxState.h 8 May 2006 16:55:31 -0000 @@ -1127,8 +1127,7 @@ void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; } void setLineCap(int lineCap1) { lineCap = lineCap1; } void setMiterLimit(double limit) { miterLimit = limit; } - void setFont(GfxFont *fontA, double fontSizeA) - { font = fontA; fontSize = fontSizeA; } + void setFont(GfxFont *fontA, double fontSizeA); void setTextMat(double a, double b, double c, double d, double e, double f) { textMat[0] = a; textMat[1] = b; textMat[2] = c; Index: poppler/GlobalParams.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/GlobalParams.cc,v retrieving revision 1.17 diff -u -u -r1.17 GlobalParams.cc --- poppler/GlobalParams.cc 4 Feb 2006 20:48:25 -0000 1.17 +++ poppler/GlobalParams.cc 8 May 2006 16:55:31 -0000 @@ -46,16 +46,20 @@ # define lockGlobalParams gLockMutex(&mutex) # define lockUnicodeMapCache gLockMutex(&unicodeMapCacheMutex) # define lockCMapCache gLockMutex(&cMapCacheMutex) +# define lockRefCnt gLockMutex(&refCntMutex) # define unlockGlobalParams gUnlockMutex(&mutex) # define unlockUnicodeMapCache gUnlockMutex(&unicodeMapCacheMutex) # define unlockCMapCache gUnlockMutex(&cMapCacheMutex) +# define unlockRefCnt gUnlockMutex(&refCntMutex) #else # define lockGlobalParams # define lockUnicodeMapCache # define lockCMapCache +# define lockRefCnt # define unlockGlobalParams # define unlockUnicodeMapCache # define unlockCMapCache +# define unlockRefCnt #endif #ifndef FC_WEIGHT_BOOK @@ -290,10 +294,13 @@ FcInit(); FCcfg = FcConfigGetCurrent(); + refCnt = 1; + #if MULTITHREADED gInitMutex(&mutex); gInitMutex(&unicodeMapCacheMutex); gInitMutex(&cMapCacheMutex); + gInitMutex(&refCntMutex); #endif initBuiltinFontTables(); @@ -980,9 +987,28 @@ gDestroyMutex(&mutex); gDestroyMutex(&unicodeMapCacheMutex); gDestroyMutex(&cMapCacheMutex); + gDestroyMutex(&refCntMutex); #endif } +void GlobalParams::incRefCnt() { + lockRefCnt; + ++refCnt; + unlockRefCnt; +} + +void GlobalParams::decRefCnt() { + GBool done; + + lockRefCnt; + done = --refCnt == 0; + unlockRefCnt; + if (done) { + delete this; + globalParams = NULL; + } +} + //------------------------------------------------------------------------ void GlobalParams::setBaseDir(char *dir) { Index: poppler/GlobalParams.h =================================================================== RCS file: /cvs/poppler/poppler/poppler/GlobalParams.h,v retrieving revision 1.6 diff -u -u -r1.6 GlobalParams.h --- poppler/GlobalParams.h 2 Feb 2006 22:50:01 -0000 1.6 +++ poppler/GlobalParams.h 8 May 2006 16:55:31 -0000 @@ -122,6 +122,9 @@ ~GlobalParams(); + void incRefCnt(); + void decRefCnt(); + void setBaseDir(char *dir); //----- accessors @@ -317,6 +320,8 @@ FcConfig *FCcfg; + int refCnt; + #ifdef ENABLE_PLUGINS GList *plugins; // list of plugins [Plugin] GList *securityHandlers; // list of loaded security handlers @@ -327,6 +332,7 @@ GooMutex mutex; GooMutex unicodeMapCacheMutex; GooMutex cMapCacheMutex; + GooMutex refCntMutex; #endif }; Index: poppler/PDFDoc.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/PDFDoc.cc,v retrieving revision 1.10 diff -u -u -r1.10 PDFDoc.cc --- poppler/PDFDoc.cc 18 Jan 2006 22:32:13 -0000 1.10 +++ poppler/PDFDoc.cc 8 May 2006 16:55:31 -0000 @@ -188,6 +188,8 @@ checkHeader(); // read xref table + if (xref) + delete xref; xref = new XRef(str); if (!xref->isOk()) { error(-1, "Couldn't read xref table"); @@ -202,6 +204,8 @@ } // read catalog + if (catalog) + delete catalog; catalog = new Catalog(xref); if (!catalog->isOk()) { error(-1, "Couldn't read page catalog"); @@ -211,6 +215,8 @@ #ifndef DISABLE_OUTLINE // read outline + if (outline) + delete outline; outline = new Outline(catalog->getOutline(), xref); #endif Index: poppler/TextOutputDev.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/TextOutputDev.cc,v retrieving revision 1.18 diff -u -u -r1.18 TextOutputDev.cc --- poppler/TextOutputDev.cc 2 May 2006 04:38:39 -0000 1.18 +++ poppler/TextOutputDev.cc 8 May 2006 16:55:31 -0000 @@ -2375,6 +2375,8 @@ //----- 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 @@ //~ 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; @@ -4080,6 +4087,9 @@ rawOrder = rawOrderA; ok = gTrue; + if (globalParams) + globalParams->incRefCnt(); + // open file needClose = gFalse; if (fileName) { @@ -4107,6 +4117,8 @@ TextOutputDev::TextOutputDev(TextOutputFunc func, void *stream, GBool physLayoutA, GBool rawOrderA) { + if (globalParams) + globalParams->incRefCnt(); outputFunc = func; outputStream = stream; needClose = gFalse; @@ -4126,6 +4138,9 @@ if (text) { delete text; } + + if (globalParams) + globalParams->decRefCnt(); } void TextOutputDev::startPage(int pageNum, GfxState *state) {