From cb39bb5e9c8007d155f986e3e217d374d0d520cd Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Dec 2013 17:56:32 -0800 Subject: Don't leak the zip structure in case of error This also erases the zip file that we created Signed-off-by: Thiago Macieira Signed-off-by: Dirk Hohndel --- qt-ui/subsurfacewebservices.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'qt-ui/subsurfacewebservices.cpp') 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) -- cgit v1.2.3-70-g09d2