Don't leak the zip structure if no dives are selected

Just move the check above the zip_open call.

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Thiago Macieira 2013-12-11 17:56:28 -08:00 committed by Dirk Hohndel
parent 1b5b562da8
commit aadf2cd19c

View file

@ -100,6 +100,12 @@ static void clear_table(struct dive_table *table)
static char *prepare_dives_for_divelogs(const bool selected)
{
const QString errPrefix("divelog.de-upload:");
if (!amount_selected) {
qDebug() << errPrefix << "no dives selected";
return NULL;
}
int i;
struct dive *dive;
FILE *f;
@ -111,7 +117,6 @@ static char *prepare_dives_for_divelogs(const bool selected)
xmlDoc *transformed;
struct zip_source *s[dive_table.nr];
struct zip *zip;
const QString errPrefix("divelog.de-upload:");
/* generate a random filename and create/open that file with zip_open */
QString tempfileQ = QDir::tempPath() + "/import-" + QString::number(qrand() % 99999999) + ".dld";
@ -123,11 +128,6 @@ static char *prepare_dives_for_divelogs(const bool selected)
free((void *)tempfile);
return NULL;
}
if (!amount_selected) {
qDebug() << errPrefix << "no dives selected";
free((void *)tempfile);
return NULL;
}
/* walk the dive list in chronological order */
for (i = 0; i < dive_table.nr; i++) {