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>
This commit is contained in:
Berthold Stoeger 2020-10-05 09:45:56 +02:00 committed by Dirk Hohndel
parent 485ac4b58f
commit 4e479677a0

View file

@ -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