diff options
author | Thiago Macieira <thiago@macieira.org> | 2013-12-11 17:56:32 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-12 03:36:16 +0100 |
commit | cb39bb5e9c8007d155f986e3e217d374d0d520cd (patch) | |
tree | 1b40b1f82f44b7dd06963aa2a3099ed877b7b6ee /qt-ui/subsurfacewebservices.cpp | |
parent | b3d59cb89080d519f5629c224cf6359f80640e19 (diff) | |
download | subsurface-cb39bb5e9c8007d155f986e3e217d374d0d520cd.tar.gz |
Don't leak the zip structure in case of error
This also erases the zip file that we created
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 | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 2b51da8d6..d863055ff 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -145,8 +145,7 @@ static char *prepare_dives_for_divelogs(const bool selected) f = tmpfile(); if (!f) { qDebug() << errPrefix << "cannot create temp file"; - free((void *)tempfile); - return NULL; + goto error_close_zip; } save_dive(f, dive); fseek(f, 0, SEEK_END); @@ -157,8 +156,7 @@ static char *prepare_dives_for_divelogs(const bool selected) qDebug() << errPrefix << "memory error"; fclose(f); free((void *)membuf); - free((void *)tempfile); - return NULL; + goto error_close_zip; } membuf[streamsize] = 0; fclose(f); @@ -171,8 +169,7 @@ static char *prepare_dives_for_divelogs(const bool selected) if (!doc) { qDebug() << errPrefix << "xml error"; free((void *)membuf); - free((void *)tempfile); - return NULL; + goto error_close_zip; } free((void *)membuf); transformed = xsltApplyStylesheet(xslt, doc, NULL); @@ -193,6 +190,13 @@ static char *prepare_dives_for_divelogs(const bool selected) zip_close(zip); xsltFreeStylesheet(xslt); return tempfile; + +error_close_zip: + zip_close(zip); + QFile::remove(tempfileQ); + free(tempfile); + xsltFreeStylesheet(xslt); + return NULL; } WebServices::WebServices(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f) |