diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-05 09:45:56 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-16 14:26:37 -0700 |
commit | 4e479677a078f43959dc7101fc47ba5afd79f344 (patch) | |
tree | 8e1303582edfd34b4ae11a166be433cee9e65d31 /core/device.cpp | |
parent | 485ac4b58fcaf2db67532fb60d7078cada7b8456 (diff) | |
download | subsurface-4e479677a078f43959dc7101fc47ba5afd79f344.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/device.cpp')
-rw-r--r-- | core/device.cpp | 8 |
1 files 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 |