summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-16 07:50:38 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-16 06:20:33 -0400
commit065c41b8347a4343d0f616542eadbb72f3d04bf1 (patch)
treedc5d0cd0e404cdb40043868d120405b9fca4c5c8
parentc61cf991e01f562cbcbd228c42e057db6690fea8 (diff)
downloadsubsurface-065c41b8347a4343d0f616542eadbb72f3d04bf1.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/dive.c8
1 files changed, 8 insertions, 0 deletions
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);