From ac3042b48bf8ee3a8f69a0384c5124c512108b11 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 19 Oct 2020 13:32:10 +0200 Subject: 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 --- core/libdivecomputer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/libdivecomputer.c') diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 6f8f4bee9..f78d23ee3 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -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; -- cgit v1.2.3-70-g09d2