From a5380bb741c1081c86353cf5cd7b506b97e02ea9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 20 Jun 2018 09:20:32 +0900 Subject: core: add free_samples helper And use it in the UI and planner code. See #1411 Signed-off-by: Dirk Hohndel --- core/dive.c | 10 ++++++++++ core/dive.h | 1 + core/planner.c | 5 +---- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/dive.c b/core/dive.c index bbfc5322d..3b3ad762d 100644 --- a/core/dive.c +++ b/core/dive.c @@ -754,6 +754,16 @@ void alloc_samples(struct divecomputer *dc, int num) } } +void free_samples(struct divecomputer *dc) +{ + if (dc) { + free(dc->sample); + dc->sample = 0; + dc->samples = 0; + dc->alloc_samples = 0; + } +} + struct sample *prepare_sample(struct divecomputer *dc) { if (dc) { diff --git a/core/dive.h b/core/dive.h index 5c7b74395..326dfe54b 100644 --- a/core/dive.h +++ b/core/dive.h @@ -747,6 +747,7 @@ extern struct dive *clone_dive(struct dive *s); extern void clear_table(struct dive_table *table); extern void alloc_samples(struct divecomputer *dc, int num); +extern void free_samples(struct divecomputer *dc); extern struct sample *prepare_sample(struct divecomputer *dc); extern void finish_sample(struct divecomputer *dc); extern void add_sample_pressure(struct sample *sample, int sensor, int mbar); diff --git a/core/planner.c b/core/planner.c index 2b58a2440..cb013799d 100644 --- a/core/planner.c +++ b/core/planner.c @@ -284,10 +284,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive, dc->when = dive->when = diveplan->when; dc->surface_pressure.mbar = diveplan->surface_pressure; dc->salinity = diveplan->salinity; - free(dc->sample); - dc->sample = NULL; - dc->samples = 0; - dc->alloc_samples = 0; + free_samples(dc); while ((ev = dc->events)) { dc->events = dc->events->next; free(ev); -- cgit v1.2.3-70-g09d2