diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-19 13:32:10 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-23 18:13:44 -0700 |
commit | ac3042b48bf8ee3a8f69a0384c5124c512108b11 (patch) | |
tree | 74e7a99cf2095bb292ffa1c23537b00aaa5b075a /core/libdivecomputer.c | |
parent | 6b1be8c4f6aee3f7793198a9e34af8fefbc2f1cc (diff) | |
download | subsurface-ac3042b48bf8ee3a8f69a0384c5124c512108b11.tar.gz |
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>
Diffstat (limited to 'core/libdivecomputer.c')
-rw-r--r-- | core/libdivecomputer.c | 3 |
1 files changed, 2 insertions, 1 deletions
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; |