From 9c6513b11dd61b723efd873384b53196b5d9d866 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Fri, 4 Jul 2014 08:50:59 +0200 Subject: Clear out old events in create_dive_from_plan Previous code where accumulating events from each iteration of the planning. This code clears the old ones before adding new ones. Fixes #595 [Dirk Hohndel: removed printf, updated comment, slightly moved the code, added parenthesis to silence warning] Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- planner.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'planner.c') diff --git a/planner.c b/planner.c index 026581de3..47835d315 100644 --- a/planner.c +++ b/planner.c @@ -246,6 +246,7 @@ static void create_dive_from_plan(struct diveplan *diveplan) struct divecomputer *dc; struct sample *sample; struct gasmix oldgasmix; + struct event *ev; cylinder_t *cyl; int oldpo2 = 0; int lasttime = 0; @@ -257,13 +258,18 @@ static void create_dive_from_plan(struct diveplan *diveplan) printf("in create_dive_from_plan\n"); dump_plan(diveplan); #endif - // reset the cylinders and clear out the samples of the displayed dive so we can restart + // reset the cylinders and clear out the samples and events of the + // displayed dive so we can restart reset_cylinders(&displayed_dive); dc = &displayed_dive.dc; free(dc->sample); dc->sample = NULL; dc->samples = 0; dc->alloc_samples = 0; + while ((ev = dc->events)) { + dc->events = dc->events->next; + free(ev); + } dp = diveplan->dp; cyl = &displayed_dive.cylinder[0]; oldgasmix = cyl->gasmix; -- cgit v1.2.3-70-g09d2