diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2018-06-20 09:20:32 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-06-20 09:27:11 +0900 |
commit | a5380bb741c1081c86353cf5cd7b506b97e02ea9 (patch) | |
tree | 7766fa0dd4c359d07d9de95631bc052c5c082e5d /core | |
parent | 49f3da3bfd9f336108fd5d4c3977b41e90f75d3f (diff) | |
download | subsurface-a5380bb741c1081c86353cf5cd7b506b97e02ea9.tar.gz |
core: add free_samples helper
And use it in the UI and planner code.
See #1411
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.c | 10 | ||||
-rw-r--r-- | core/dive.h | 1 | ||||
-rw-r--r-- | core/planner.c | 5 |
3 files changed, 12 insertions, 4 deletions
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); |