summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-12-27 13:18:17 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-12-27 13:18:41 -0800
commitd3118bedd4f091aedbd941b1040aea2173bd1fed (patch)
treea7fd2361850306c81e75ccaaf6a9df3d927d8b67
parent43c1c0a1d1fe111520a090a9e27414f8ef4754ac (diff)
downloadsubsurface-d3118bedd4f091aedbd941b1040aea2173bd1fed.tar.gz
Cleanup: correctly prevent memory leak
The previous attempt to fix this in commit 652e382e68 ("Cleanup: avoid a few memory leaks") was clearly bogus. Oops. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/ostctools.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/core/ostctools.c b/core/ostctools.c
index fbee65b2f..e56b50f5d 100644
--- a/core/ostctools.c
+++ b/core/ostctools.c
@@ -62,7 +62,7 @@ void ostctools_import(const char *file, struct dive_table *divetable)
report_error(failed_to_read_msg, file);
free(uc_tmp);
free(ostcdive);
- goto out;
+ goto close_out;
}
ostcdive->number = uc_tmp[0] + (uc_tmp[1] << 8);
free(uc_tmp);
@@ -74,7 +74,7 @@ void ostctools_import(const char *file, struct dive_table *divetable)
report_error(failed_to_read_msg, file);
free(uc_tmp);
free(ostcdive);
- goto out;
+ goto close_out;
}
serial = uc_tmp[0] + (uc_tmp[1] << 8);
free(uc_tmp);
@@ -90,7 +90,7 @@ void ostctools_import(const char *file, struct dive_table *divetable)
if (ferror(archive)) {
report_error(failed_to_read_msg, file);
free(ostcdive);
- goto out;
+ goto close_out;
}
// Try to determine the dc family based on the header type
@@ -108,8 +108,7 @@ void ostctools_import(const char *file, struct dive_table *divetable)
default:
report_error(translate("gettextFromC", "Unknown DC in dive %d"), ostcdive->number);
free(ostcdive);
- fclose(archive);
- goto out;
+ goto close_out;
}
}
@@ -140,8 +139,7 @@ void ostctools_import(const char *file, struct dive_table *divetable)
if (ret == 0) {
report_error(translate("gettextFromC", "Unknown DC in dive %d"), ostcdive->number);
free(ostcdive);
- fclose(archive);
- goto out;
+ goto close_out;
}
tmp = calloc(strlen(devdata->vendor) + strlen(devdata->model) + 28, 1);
sprintf(tmp, "%s %s (Imported from OSTCTools)", devdata->vendor, devdata->model);
@@ -175,9 +173,10 @@ void ostctools_import(const char *file, struct dive_table *divetable)
record_dive_to_table(ostcdive, divetable);
mark_divelist_changed(true);
sort_table(divetable);
+
+close_out:
fclose(archive);
out:
- free(archive);
free(devdata);
free(buffer);
}