From 90f65593e1c80f890851d469e467150b91198a35 Mon Sep 17 00:00:00 2001 From: Igor Slepchin Date: Wed, 8 Feb 2012 16:19:06 -0500 Subject: [PATCH 2/2] Fix memory leaks in getInfoString() and mapEncodingToHtml. Bug 45805. --- utils/HtmlOutputDev.cc | 29 ++++++++++++++--------------- utils/HtmlOutputDev.h | 6 ++++-- utils/pdftohtml.cc | 1 - 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc index cf6b5a7..b995b93 100644 --- a/utils/HtmlOutputDev.cc +++ b/utils/HtmlOutputDev.cc @@ -261,8 +261,9 @@ void HtmlString::endString() // HtmlPage //------------------------------------------------------------------------ -HtmlPage::HtmlPage(GBool rawOrder, char *imgExtVal) { +HtmlPage::HtmlPage(GBool rawOrder, char *imgExtVal, char *htmlEncoding) { this->rawOrder = rawOrder; + this->htmlEncoding = htmlEncoding; curStr = NULL; yxStrings = NULL; xyStrings = NULL; @@ -764,7 +765,6 @@ void HtmlPage::dumpAsXML(FILE* f,int page){ int HtmlPage::dumpComplexHeaders(FILE * const file, FILE *& pageFile, int page) { GooString* tmp; - char* htmlEncoding; if( !noframes ) { @@ -791,7 +791,6 @@ int HtmlPage::dumpComplexHeaders(FILE * const file, FILE *& pageFile, int page) delete tmp; - htmlEncoding = HtmlOutputDev::mapEncodingToHtml(globalParams->getTextEncodingName()); if (!singleHtml) fprintf(pageFile, "\n", htmlEncoding); else @@ -986,22 +985,26 @@ static char* HtmlEncodings[][2] = { }; -char* HtmlOutputDev::mapEncodingToHtml(GooString* encoding) +char* HtmlOutputDev::getHtmlEncoding() { + GooString *encoding = globalParams->getTextEncodingName(); + char* enc = encoding->getCString(); for(int i = 0; HtmlEncodings[i][0] != NULL; i++) { if( strcmp(enc, HtmlEncodings[i][0]) == 0 ) { - return HtmlEncodings[i][1]; + enc = HtmlEncodings[i][1]; } } - return enc; + + enc = strdup(enc); + delete encoding; + return enc; } void HtmlOutputDev::doFrame(int firstPage){ GooString* fName=new GooString(Docname); - char* htmlEncoding; fName->append(".html"); if (!(fContentsFrame = fopen(fName->getCString(), "w"))){ @@ -1017,7 +1020,6 @@ void HtmlOutputDev::doFrame(int firstPage){ fputs("\n",fContentsFrame); fputs("\n",fContentsFrame); fprintf(fContentsFrame,"\n%s",docTitle->getCString()); - htmlEncoding = mapEncodingToHtml(globalParams->getTextEncodingName()); fprintf(fContentsFrame, "\n\n", htmlEncoding); dumpMetaVars(fContentsFrame); fprintf(fContentsFrame, "\n"); @@ -1040,8 +1042,6 @@ HtmlOutputDev::HtmlOutputDev(char *fileName, char *title, char *extension, GBool rawOrder, int firstPage, GBool outline) { - char *htmlEncoding; - fContentsFrame = NULL; docTitle = new GooString(title); pages = NULL; @@ -1054,7 +1054,8 @@ HtmlOutputDev::HtmlOutputDev(char *fileName, char *title, //pageNum=firstPage; // open file needClose = gFalse; - pages = new HtmlPage(rawOrder, extension); + htmlEncoding = getHtmlEncoding(); + pages = new HtmlPage(rawOrder, extension, htmlEncoding); glMetaVars = new GooList(); glMetaVars->append(new HtmlMetaVar("generator", "pdftohtml 0.36")); @@ -1127,7 +1128,6 @@ HtmlOutputDev::HtmlOutputDev(char *fileName, char *title, delete right; } - htmlEncoding = mapEncodingToHtml(globalParams->getTextEncodingName()); if (xml) { fprintf(page, "\n", htmlEncoding); @@ -1171,6 +1171,8 @@ HtmlOutputDev::~HtmlOutputDev() { } if (pages) delete pages; + + free(htmlEncoding); } void HtmlOutputDev::startPage(int pageNum, GfxState *state) { @@ -1595,9 +1597,6 @@ GBool HtmlOutputDev::dumpDocOutline(PDFDoc* doc) delete str; bClose = gTrue; - char *htmlEncoding = - HtmlOutputDev::mapEncodingToHtml(globalParams->getTextEncodingName()); - fprintf(output, "\n" \ "\n" \ diff --git a/utils/HtmlOutputDev.h b/utils/HtmlOutputDev.h index 4943bd9..73d07e8 100644 --- a/utils/HtmlOutputDev.h +++ b/utils/HtmlOutputDev.h @@ -121,7 +121,7 @@ class HtmlPage { public: // Constructor. - HtmlPage(GBool rawOrder, char *imgExtVal); + HtmlPage(GBool rawOrder, char *imgExtVal, char* htmlEncoding); // Destructor. ~HtmlPage(); @@ -195,6 +195,7 @@ private: int pageWidth; int pageHeight; int firstPage; // used to begin the numeration of pages + char *htmlEncoding; friend class HtmlOutputDev; }; @@ -311,7 +312,7 @@ public: private: // convert encoding into a HTML standard, or encoding->getCString if not // recognized - static char* mapEncodingToHtml(GooString* encoding); + static char* getHtmlEncoding(); void doProcessLink(AnnotLink *link); GooString* getLinkDest(AnnotLink *link,Catalog *catalog); void dumpMetaVars(FILE *); @@ -337,6 +338,7 @@ private: GooList *glMetaVars; Catalog *catalog; Page *docPage; + char *htmlEncoding; friend class HtmlPage; }; diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc index 0bc1ca7..fcfa248 100644 --- a/utils/pdftohtml.cc +++ b/utils/pdftohtml.cc @@ -528,7 +528,6 @@ static GooString* getInfoString(Dict *infoDict, char *key) { rawString = obj.getString(); // Convert rawString to unicode - encodedString = new GooString(); if (rawString->hasUnicodeMarker()) { isUnicode = gTrue; unicodeLength = (obj.getString()->getLength() - 2) / 2; -- 1.7.7.6