diff options
author | Thiago Macieira <thiago@macieira.org> | 2013-12-11 17:56:30 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-12 03:35:37 +0100 |
commit | 04ec3cf31f4ff29c18381cddf22259604de7cb97 (patch) | |
tree | 3ecbae5bd7179d9c4a0eae72f416694df834db29 /qt-ui/subsurfacewebservices.cpp | |
parent | a17880ca025a36d4ffda1da883bc01632f09dddd (diff) | |
download | subsurface-04ec3cf31f4ff29c18381cddf22259604de7cb97.tar.gz |
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 <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/subsurfacewebservices.cpp')
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
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; } |