From a8d2b2ff70826d5f24e908378391491840b13adf Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 18 Apr 2023 09:31:42 +0200 Subject: [PATCH] divelog: fix erroneous use of std::move() This has to be applied to the object, not the pointer to the object. Fixes a double-free crash introduced in 8cd451f. Alternatively, we could use std::swap() for C++98 charm and perhaps better readability for people unfamiliar with C++11. Nowadays, std::move() is more idiomatic though. Shrug. Reported-by: Michael Keller Signed-off-by: Berthold Stoeger --- core/divelog.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/divelog.cpp b/core/divelog.cpp index 321a3684b..158121180 100644 --- a/core/divelog.cpp +++ b/core/divelog.cpp @@ -40,8 +40,8 @@ divelog::divelog(divelog &&log) : dives(new dive_table), trips(new trip_table), sites(new dive_site_table), - devices(std::move(log.devices)), - filter_presets(std::move(log.filter_presets)) + devices(new device_table), + filter_presets(new filter_preset_table) { *dives = empty_dive_table; *trips = empty_trip_table; @@ -49,6 +49,8 @@ divelog::divelog(divelog &&log) : move_dive_table(log.dives, dives); move_trip_table(log.trips, trips); move_dive_site_table(log.sites, sites); + *devices = std::move(*log.devices); + *filter_presets = std::move(*log.filter_presets); } struct divelog &divelog::operator=(divelog &&log) @@ -56,8 +58,8 @@ struct divelog &divelog::operator=(divelog &&log) move_dive_table(log.dives, dives); move_trip_table(log.trips, trips); move_dive_site_table(log.sites, sites); - devices = std::move(log.devices); - filter_presets = std::move(log.filter_presets); + *devices = std::move(*log.devices); + *filter_presets = std::move(*log.filter_presets); return *this; }