From 5ed4876ad29c2952d84814b586572f5515afba94 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 17 Nov 2014 11:30:49 +0000 Subject: Continue cleanup of string copying in equipment Slowly trying to track down all spots where we copy string pointers instead of string data. And making sure that we free those pointers before overwriting them. Signed-off-by: Dirk Hohndel --- dive.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dive.c b/dive.c index 3e938c516..6a16706c0 100644 --- a/dive.c +++ b/dive.c @@ -512,8 +512,11 @@ void selective_copy_dive(struct dive *s, struct dive *d, struct dive_components if (what.cylinders) copy_cylinders(s, d, false); if (what.weights) - for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) + for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) { + free((void *)d->weightsystem[i].description); d->weightsystem[i] = s->weightsystem[i]; + d->weightsystem[i].description = copy_string(s->weightsystem[i].description); + } } #undef CONDITIONAL_COPY_STRING @@ -567,11 +570,14 @@ void copy_cylinders(struct dive *s, struct dive *d, bool used_only) if (!s || !d) return; for (i = 0; i < MAX_CYLINDERS; i++) { + free((void *)d->cylinder[i].type.description); memset(&d->cylinder[i], 0, sizeof(cylinder_t)); if (!used_only || is_cylinder_used(s, i)) { d->cylinder[i].type = s->cylinder[i].type; + d->cylinder[i].type.description = copy_string(s->cylinder[i].type.description); d->cylinder[i].gasmix = s->cylinder[i].gasmix; d->cylinder[i].depth = s->cylinder[i].depth; + d->cylinder[i].cylinder_use = s->cylinder[i].cylinder_use; d->cylinder[i].manually_added = true; } } -- cgit v1.2.3-70-g09d2