Skip to content

Commit

Permalink
Merge pull request wkhtmltopdf#22 from poizan42/master
Browse files Browse the repository at this point in the history
Don't return freed memory from wkhtmltopdf_phase_description and wkhtmltopdf_progress_string
  • Loading branch information
antialize committed Jul 9, 2013
2 parents 5b394ad + de316ef commit 8344e44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib/pdf_c_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <QApplication>
#include <QWebFrame>

#include <QHash>

#include "dllbegin.inc"
/**
* \page pagesettings Setting
Expand Down Expand Up @@ -597,7 +599,14 @@ CAPI(int) wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter) {
* \sa wkhtmltopdf_current_phase, wkhtmltopdf_phase_description
*/
CAPI(const char *) wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase) {
return reinterpret_cast<MyPdfConverter *>(converter)->converter.phaseDescription(phase).toUtf8().constData();
MyPdfConverter* conv = reinterpret_cast<MyPdfConverter *>(converter);
QString pd = conv->converter.phaseDescription(phase);
if (!conv->utf8StringCache.contains(pd))
{
return conv->utf8StringCache.insert(pd, pd.toUtf8()).value().constData();
}
else
return conv->utf8StringCache[pd].constData();
}

/**
Expand All @@ -611,7 +620,12 @@ CAPI(const char *) wkhtmltopdf_phase_description(wkhtmltopdf_converter * convert
* \sa wkhtmltopdf_set_progress_changed_callback
*/
CAPI(const char *) wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter) {
return reinterpret_cast<MyPdfConverter *>(converter)->converter.progressString().toUtf8().constData();
MyPdfConverter* conv = reinterpret_cast<MyPdfConverter *>(converter);
QString ps = conv->converter.progressString();
if (!conv->utf8StringCache.contains(ps))
return conv->utf8StringCache.insert(ps, ps.toUtf8()).value().constData();
else
return conv->utf8StringCache[ps].constData();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pdf_c_bindings_p.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "pdf.h"
#include "pdfconverter.hh"
#include <QObject>
#include <QHash>
#include <vector>

#include "dllbegin.inc"
Expand All @@ -46,6 +47,7 @@ public:

wkhtmltopdf::settings::PdfGlobal * globalSettings;
std::vector<wkhtmltopdf::settings::PdfObject *> objectSettings;
QHash<QString, QByteArray> utf8StringCache;

MyPdfConverter(wkhtmltopdf::settings::PdfGlobal * gs);
~MyPdfConverter();
Expand Down

0 comments on commit 8344e44

Please sign in to comment.