From 04ec3cf31f4ff29c18381cddf22259604de7cb97 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Dec 2013 17:56:30 -0800 Subject: Hoist the getting of the XSLT style-sheet out of the loop We don't need to get it for every file, since it's the same. This also avoids leaking temporary files and memory if the stylesheet cannot be found. Signed-off-by: Thiago Macieira Signed-off-by: Dirk Hohndel --- qt-ui/subsurfacewebservices.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'qt-ui/subsurfacewebservices.cpp') diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index cdf1f493b..6be63fbad 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -118,6 +118,12 @@ static char *prepare_dives_for_divelogs(const bool selected) struct zip_source *s[dive_table.nr]; struct zip *zip; + xslt = get_stylesheet("divelogs-export.xslt"); + if (!xslt) { + qDebug() << errPrefix << "missing stylesheet"; + return NULL; + } + /* generate a random filename and create/open that file with zip_open */ QString tempfileQ = QDir::tempPath() + "/import-" + QString::number(qrand() % 99999999) + ".dld"; tempfile = strdup(tempfileQ.toLocal8Bit().data()); @@ -166,15 +172,7 @@ static char *prepare_dives_for_divelogs(const bool selected) return NULL; } free((void *)membuf); - // this call is overriding our local variable tempfile! not a good sign! - xslt = get_stylesheet("divelogs-export.xslt"); - if (!xslt) { - qDebug() << errPrefix << "missing stylesheet"; - free((void *)tempfile); - return NULL; - } transformed = xsltApplyStylesheet(xslt, doc, NULL); - xsltFreeStylesheet(xslt); xmlDocDumpMemory(transformed, (xmlChar **) &membuf, (int *)&streamsize); xmlFreeDoc(doc); xmlFreeDoc(transformed); @@ -190,6 +188,7 @@ static char *prepare_dives_for_divelogs(const bool selected) } } zip_close(zip); + xsltFreeStylesheet(xslt); return tempfile; } -- cgit v1.2.3-70-g09d2