From 4e479677a078f43959dc7101fc47ba5afd79f344 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 5 Oct 2020 09:45:56 +0200 Subject: cleanup: fix tiny memory hole in device.cpp empty_string() returns true for "". Thus, we can't simply overwrite the pointer if empyt_string() returns true, but must free the string regardless. The joys of C memory management! Signed-off-by: Berthold Stoeger --- core/device.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/device.cpp b/core/device.cpp index c47cc821f..07ef0945f 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -238,10 +238,14 @@ extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid) if (!node) return; - if (!node->serialNumber.isEmpty() && empty_string(dc->serial)) + if (!node->serialNumber.isEmpty() && empty_string(dc->serial)) { + free((void *)dc->serial); dc->serial = copy_qstring(node->serialNumber); - if (!node->firmware.isEmpty() && empty_string(dc->fw_version)) + } + if (!node->firmware.isEmpty() && empty_string(dc->fw_version)) { + free((void *)dc->fw_version); dc->fw_version = copy_qstring(node->firmware); + } } void device::showchanges(const QString &n, const QString &s, const QString &f) const -- cgit v1.2.3-70-g09d2