When copying dives, make copies of samples/events in first DC

We carefully copied the dive computers and their samples and events, but
only for the second and later DCs. For the first DC we simply copied the
pointers but not what they were pointing at. So when the copied dive was
freed, those pointers in the original went to freed memory.

Not good.

Fixes #599

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-06 11:02:28 -07:00
parent 0c24d7d6bd
commit d97c49ba39

6
dive.c
View file

@ -341,9 +341,13 @@ void copy_dive(struct dive *s, struct dive *d)
d->location = copy_string(s->location); d->location = copy_string(s->location);
d->notes = copy_string(s->notes); d->notes = copy_string(s->notes);
d->suit = copy_string(s->suit); d->suit = copy_string(s->suit);
STRUCTURED_LIST_COPY(struct divecomputer, s->dc.next, d->dc.next, copy_dc);
STRUCTURED_LIST_COPY(struct picture, s->picture_list, d->picture_list, copy_pl); 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 tag_entry, s->tag_list, d->tag_list, copy_tl);
STRUCTURED_LIST_COPY(struct divecomputer, s->dc.next, d->dc.next, copy_dc);
/* this only copied dive computers 2 and up. The first dive computer is part
* of the struct dive, so let's make copies of its samples and events */
copy_samples(&s->dc, &d->dc);
copy_events(&s->dc, &d->dc);
} }
/* make a clone of the source dive and clean out the source dive; /* make a clone of the source dive and clean out the source dive;