From 2776a2fe48c8c7db73d3fe369bbf7746741462ae Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 26 May 2024 16:36:53 +0200 Subject: [PATCH] import: fix memory leak when importing dives A long standing issue: the dives_to_add, etc. tables need to be manually freed. This kind of problem wouldn't arise with proper C++ data structures. Signed-off-by: Berthold Stoeger --- commands/command_divelist.cpp | 5 +++++ core/divelist.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index b6901c523..6ca13f5f9 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -521,6 +521,11 @@ ImportDives::ImportDives(struct divelog *log, int flags, const QString &source) continue; filterPresetsToAdd.emplace_back(preset.name, preset.data); } + + free(dives_to_add.dives); + free(dives_to_remove.dives); + free(trips_to_add.trips); + free(sites_to_add.dive_sites); } bool ImportDives::workToBeDone() diff --git a/core/divelist.c b/core/divelist.c index 8c677498a..c6d1a7e31 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1007,6 +1007,10 @@ void add_imported_dives(struct divelog *import_log, int flags) current_dive = divelog.dives->nr > 0 ? divelog.dives->dives[divelog.dives->nr - 1] : NULL; free_device_table(devices_to_add); + free(dives_to_add.dives); + free(dives_to_remove.dives); + free(trips_to_add.trips); + free(dive_sites_to_add.dive_sites); /* Inform frontend of reset data. This should reset all the models. */ emit_reset_signal();