From 065c41b8347a4343d0f616542eadbb72f3d04bf1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 16 Oct 2018 07:50:38 +0200 Subject: Core: copy / free serial and fw_version items of struct divecomputer The serial and fw_version strings of struct divecomputer were copied by pointer. This worked because they were never freed or modified. Instead, do a deep copy of the strings and free them when appropriate. Signed-off-by: Berthold Stoeger --- core/dive.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'core/dive.c') diff --git a/core/dive.c b/core/dive.c index 303288b4e..0912f0388 100644 --- a/core/dive.c +++ b/core/dive.c @@ -515,6 +515,8 @@ static void copy_dc(const struct divecomputer *sdc, struct divecomputer *ddc) { *ddc = *sdc; ddc->model = copy_string(sdc->model); + ddc->serial = copy_string(sdc->serial); + ddc->fw_version = copy_string(sdc->fw_version); copy_samples(sdc, ddc); copy_events(sdc, ddc); STRUCTURED_LIST_COPY(struct extra_data, sdc->extra_data, ddc->extra_data, copy_extra_data); @@ -2976,6 +2978,8 @@ static void free_dc_contents(struct divecomputer *dc) { free(dc->sample); free((void *)dc->model); + free((void *)dc->serial); + free((void *)dc->fw_version); free_events(dc->events); STRUCTURED_LIST_FREE(struct extra_data, dc->extra_data, free_extra_data); } @@ -3091,6 +3095,8 @@ static void copy_dive_computer(struct divecomputer *res, const struct divecomput { *res = *a; res->model = copy_string(a->model); + res->serial = copy_string(a->serial); + res->fw_version = copy_string(a->fw_version); STRUCTURED_LIST_COPY(struct extra_data, a->extra_data, res->extra_data, copy_extra_data); res->samples = res->alloc_samples = 0; res->sample = NULL; @@ -4153,6 +4159,8 @@ void delete_current_divecomputer(void) struct divecomputer *fdc = dc->next; free(dc->sample); free((void *)dc->model); + free((void *)dc->serial); + free((void *)dc->fw_version); free_events(dc->events); memcpy(dc, fdc, sizeof(struct divecomputer)); free(fdc); -- cgit v1.2.3-70-g09d2