Index: ChangeLog =================================================================== RCS file: /cvs/poppler/poppler/ChangeLog,v retrieving revision 1.361 diff -u -u -r1.361 ChangeLog --- ChangeLog 14 May 2006 16:11:54 -0000 1.361 +++ ChangeLog 16 May 2006 20:36:06 -0000 @@ -1,3 +1,17 @@ +2006-05-16 Carlos Garcia Campos + + * glib/Makefile.am: + * glib/poppler-action.cc: + * glib/poppler-document.cc: + * glib/poppler-global-params.cc: + * glib/poppler-global-params.h: + * glib/poppler-page.cc: + * glib/poppler-private.h: + * poppler/TextOutputDev.cc: + + Fix several memory leaks. + 2006-05-14 Albert Astals Cid * poppler/FontInfo.cc: Fix possible crash, half patch Index: glib/Makefile.am =================================================================== RCS file: /cvs/poppler/poppler/glib/Makefile.am,v retrieving revision 1.15 diff -u -u -r1.15 Makefile.am --- glib/Makefile.am 12 Apr 2006 02:07:07 -0000 1.15 +++ glib/Makefile.am 16 May 2006 20:36:06 -0000 @@ -60,6 +60,7 @@ poppler-document.h \ poppler-page.h \ poppler-attachment.h \ + poppler-global-params.h \ poppler.h poppler_glib_includedir = $(includedir)/poppler/glib @@ -76,6 +77,7 @@ poppler-document.cc \ poppler-page.cc \ poppler-attachment.cc \ + poppler-global-params.cc \ poppler.cc \ poppler-private.h 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 16 May 2006 20:36:06 -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 16 May 2006 20:36:07 -0000 @@ -32,7 +32,6 @@ #include "poppler.h" #include "poppler-private.h" -#include "poppler-attachment.h" #include "poppler-enums.h" enum { @@ -86,10 +85,8 @@ char *filename; document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL); - - if (!globalParams) { - globalParams = new GlobalParams("/etc/xpdfrc"); - } + + document->global_params = poppler_global_params_get (); filename = g_filename_from_uri (uri, NULL, error); if (!filename) @@ -178,6 +175,11 @@ delete document->output_dev; delete document->doc; + + if (document->global_params) { + g_object_unref (document->global_params); + document->global_params = NULL; + } } /** @@ -330,26 +332,26 @@ poppler_document_find_dest (PopplerDocument *document, const gchar *link_name) { - PopplerDest *dest = NULL; - LinkDest *link_dest = NULL; - UGooString *g_link_name; - - g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); - g_return_val_if_fail (link_name != NULL, NULL); - - g_link_name = new UGooString (link_name); + PopplerDest *dest = NULL; + LinkDest *link_dest = NULL; + UGooString *g_link_name; - if (g_link_name) { - link_dest = document->doc->findDest (g_link_name); - delete g_link_name; - } - - if (link_dest) { - dest = _poppler_dest_new_goto (document, link_dest); - delete link_dest; - } + g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL); + g_return_val_if_fail (link_name != NULL, NULL); + + g_link_name = new UGooString (link_name); + + if (g_link_name) { + link_dest = document->doc->findDest (g_link_name); + delete g_link_name; + } - return dest; + if (link_dest) { + dest = _poppler_dest_new_goto (document, link_dest); + delete link_dest; + } + + return dest; } char *_poppler_goo_string_to_utf8(GooString *s) @@ -411,7 +413,7 @@ 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 +430,8 @@ } 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 +441,12 @@ 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 +454,12 @@ scanned_items = sscanf (date_string, "%2d%3d%2d%2d%2d%2d%2d", ¢ury, &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 +477,15 @@ /* 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 +552,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 +564,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 ()) { @@ -768,6 +788,7 @@ static void poppler_document_init (PopplerDocument *document) { + document->global_params = NULL; } /* PopplerIndexIter: For determining the index of a tree */ @@ -1013,11 +1034,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-global-params.cc =================================================================== RCS file: glib/poppler-global-params.cc diff -N glib/poppler-global-params.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ glib/poppler-global-params.cc 16 May 2006 20:36:07 -0000 @@ -0,0 +1,67 @@ +/* poppler-global-params.cc: glib interface to poppler + * Copyright (C) 2006, Carlos Garcia Campos + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include "poppler-global-params.h" + +static void poppler_global_params_init (PopplerGlobalParams *gp); +static void poppler_global_params_class_init (PopplerGlobalParamsClass *klass); +static void poppler_global_params_finalize (GObject *object); + +static PopplerGlobalParams *global_params = NULL; + +G_DEFINE_TYPE (PopplerGlobalParams, poppler_global_params, G_TYPE_OBJECT); + +static void +poppler_global_params_init (PopplerGlobalParams *gp) +{ + globalParams = new GlobalParams("/etc/xpdfrc"); +} + +static void +poppler_global_params_class_init (PopplerGlobalParamsClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = poppler_global_params_finalize; +} + +static void +poppler_global_params_finalize (GObject *object) +{ + if (globalParams) { + delete globalParams; + globalParams = NULL; + } + + global_params = NULL; +} + +PopplerGlobalParams * +poppler_global_params_get (void) +{ + if (!global_params) { + global_params = POPPLER_GLOBAL_PARAMS (g_object_new (POPPLER_TYPE_GLOBAL_PARAMS, + NULL)); + } else { + g_object_ref (global_params); + } + + return global_params; +} Index: glib/poppler-global-params.h =================================================================== RCS file: glib/poppler-global-params.h diff -N glib/poppler-global-params.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ glib/poppler-global-params.h 16 May 2006 20:36:07 -0000 @@ -0,0 +1,45 @@ +/* poppler-global-params.h: glib interface to poppler + * Copyright (C) 2006, Carlos Garcia Campos + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __POPPLER_GLOBAL_PARAMS_H__ +#define __POPPLER_GLOBAL_PARAMS_H__ + +#include + +G_BEGIN_DECLS + +#define POPPLER_TYPE_GLOBAL_PARAMS (poppler_global_params_get_type ()) +#define POPPLER_GLOBAL_PARAMS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_GLOBAL_PARAMS, PopplerGlobalParams)) + +typedef struct _PopplerGlobalParams PopplerGlobalParams; +typedef struct _PopplerGlobalParamsClass PopplerGlobalParamsClass; + +struct _PopplerGlobalParams { + GObject parent; +}; + +struct _PopplerGlobalParamsClass { + GObjectClass parent_class; +}; + +GType poppler_global_params_get_type (void) G_GNUC_CONST; +PopplerGlobalParams *poppler_global_params_get (void); + +G_END_DECLS + +#endif /* __POPPLER_GLOBAL_PARAMS_H__ */ 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 16 May 2006 20:36:07 -0000 @@ -56,6 +56,7 @@ poppler_page->document = document; poppler_page->page = page; poppler_page->index = index; + poppler_page->global_params = poppler_global_params_get (); return poppler_page; } @@ -70,6 +71,11 @@ if (page->text_dev != NULL) delete page->text_dev; + if (page->global_params) { + g_object_unref (page->global_params); + page->global_params = NULL; + } + /* page->page is owned by the document */ } @@ -808,6 +814,7 @@ static void poppler_page_init (PopplerPage *page) { + page->global_params = NULL; } @@ -860,6 +867,8 @@ map_list = g_list_prepend (map_list, mapping); } + delete links; + return map_list; } Index: glib/poppler-private.h =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-private.h,v retrieving revision 1.15 diff -u -u -r1.15 poppler-private.h --- glib/poppler-private.h 16 Apr 2006 22:59:44 -0000 1.15 +++ glib/poppler-private.h 16 May 2006 20:36:07 -0000 @@ -11,6 +11,7 @@ #include #include "poppler-attachment.h" +#include "poppler-global-params.h" #if defined (HAVE_CAIRO) #include @@ -22,6 +23,7 @@ { GObject parent_instance; PDFDoc *doc; + PopplerGlobalParams *global_params; #if defined (HAVE_CAIRO) CairoOutputDev *output_dev; @@ -56,6 +58,7 @@ int index; TextOutputDev *text_dev; Gfx *gfx; + PopplerGlobalParams *global_params; }; PopplerPage *_poppler_page_new (PopplerDocument *document, 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 16 May 2006 20:36:08 -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; @@ -3375,6 +3382,8 @@ word->charcode[i], 1, NULL, 0); out->endString(state); + + delete string; } void TextWord::visitSelection(TextSelectionVisitor *visitor,