libdc: free value strings given by libdc's dc_parser_get_field()

Apparently libdc gives us copies of strings. The API is very
scary, because (at least according to my reading of the code),
the key/value pair may be stored in a cache. Thus on free()ing
the string in the cache becomes invalid and we must not access
it twice. Very obscure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-19 13:32:10 +02:00 committed by Dirk Hohndel
parent 6b1be8c4f6
commit ac3042b48b

View file

@ -564,7 +564,7 @@ static void set_dc_serial(struct divecomputer *dc, const char *serial)
{
const struct device *device;
dc->serial = serial;
dc->serial = strdup(serial);
if ((device = get_device_for_dc(&device_table, dc)) != NULL)
dc->deviceid = device_get_id(device);
@ -723,6 +723,7 @@ static dc_status_t libdc_header_parser(dc_parser_t *parser, device_data_t *devda
if (!str.desc || !str.value)
break;
parse_string_field(devdata, dive, &str);
free((void *)str.value); // libdc gives us copies of the value-string.
}
dc_divemode_t divemode;