summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-14 13:33:12 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-14 13:45:54 -0800
commit8d766e13e258e206edb2c2746895845de942fa8e (patch)
tree435f3287c34cd20e3da037940dd5349f45861c56 /dive.c
parent1055b5afd35526c552eafcaf26d5f1d9aac43c86 (diff)
downloadsubsurface-8d766e13e258e206edb2c2746895845de942fa8e.tar.gz
Make sure we always have copies of equipment descriptions
Having pointers copied around that might get freed elsewhere could be a problem. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 126453bed..0c0e64972 100644
--- a/dive.c
+++ b/dive.c
@@ -434,6 +434,10 @@ void clear_dive(struct dive *d)
taglist_free(d->tag_list);
STRUCTURED_LIST_FREE(struct divecomputer, d->dc.next, free_dc);
STRUCTURED_LIST_FREE(struct picture, d->picture_list, free_pic);
+ for (int i = 0; i < MAX_CYLINDERS; i++)
+ free((void *)d->cylinder[i].type.description);
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ free((void *)d->weightsystem[i].description);
memset(d, 0, sizeof(struct dive));
}
@@ -452,6 +456,10 @@ void copy_dive(struct dive *s, struct dive *d)
d->location = copy_string(s->location);
d->notes = copy_string(s->notes);
d->suit = copy_string(s->suit);
+ for (int i = 0; i < MAX_CYLINDERS; i++)
+ d->cylinder[i].type.description = copy_string(s->cylinder[i].type.description);
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
STRUCTURED_LIST_COPY(struct picture, s->picture_list, d->picture_list, copy_pl);
STRUCTURED_LIST_COPY(struct tag_entry, s->tag_list, d->tag_list, copy_tl);
STRUCTURED_LIST_COPY(struct divecomputer, s->dc.next, d->dc.next, copy_dc);