From 1c00f9f233afac6e270da6bc53fd9f52a5963388 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 20 Aug 2022 17:24:45 +0200 Subject: [PATCH] core: use free_dive() to free dive One would think that calling free() on a dive structure, as the code did in some places, would lead to a memory leak. (Insert rant about C memory management.) Signed-off-by: Berthold Stoeger --- core/import-csv.c | 2 +- core/libdivecomputer.c | 4 ++-- core/liquivision.c | 2 +- core/uemis-downloader.c | 11 ++--------- qt-models/diveplannermodel.cpp | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/core/import-csv.c b/core/import-csv.c index 14fd51816..8567f263e 100644 --- a/core/import-csv.c +++ b/core/import-csv.c @@ -609,7 +609,7 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab */ if (readfile(csv, &memcsv) < 0) { - free(dive); + free_dive(dive); return report_error(translate("gettextFromC", "Poseidon import failed: unable to read '%s'"), csv); } lineptr = memcsv.buffer; diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index d136920af..043a63e35 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -821,7 +821,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, char *date_string = get_dive_date_c_string(dive->when); dev_info(devdata, translate("gettextFromC", "Already downloaded dive at %s"), date_string); free(date_string); - free(dive); + free_dive(dive); return false; } @@ -844,7 +844,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, error_exit: dc_parser_destroy(parser); - free(dive); + free_dive(dive); return true; } diff --git a/core/liquivision.c b/core/liquivision.c index ef326f0a2..d7cd100d0 100644 --- a/core/liquivision.c +++ b/core/liquivision.c @@ -433,7 +433,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int //DEBUG save_dives("/tmp/test.xml"); // if we bailed out of the loop, the dive hasn't been recorded and dive hasn't been set to NULL - free(dive); + free_dive(dive); } int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c index 48309bc4d..8b49516a4 100644 --- a/core/uemis-downloader.c +++ b/core/uemis-downloader.c @@ -857,14 +857,7 @@ static bool uemis_delete_dive(device_data_t *devdata, uint32_t diveid) } if (dive) { devdata->download_table->dives[--devdata->download_table->nr] = NULL; - - free(dive->dc.sample); - free((void *)dive->notes); - free((void *)dive->diveguide); - free((void *)dive->buddy); - free((void *)dive->suit); - taglist_free(dive->tag_list); - free(dive); + free_dive(dive); return true; } @@ -1030,7 +1023,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char * if (dive->dc.diveid) { record_dive_to_table(dive, devdata->download_table); } else { /* partial dive */ - free(dive); + free_dive(dive); free(buf); return false; } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 1f77ab5ca..17be91a29 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -1272,7 +1272,7 @@ finish: free(original_plan); free(save); free(cache); - free(dive); + free_dive(dive); } void DivePlannerPointsModel::computeVariationsDone(QString variations)