summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/dive.c10
-rw-r--r--core/dive.h1
-rw-r--r--core/planner.c5
-rw-r--r--mobile-widgets/qmlmanager.cpp15
4 files changed, 16 insertions, 15 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);
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 8db7df7df..90cf97b2b 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -923,14 +923,10 @@ bool QMLManager::checkDuration(DiveObjectHelper *myDive, struct dive *d, QString
m = r6.cap(1).toInt();
}
d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s;
- if (same_string(d->dc.model, "manually added dive")) {
- free(d->dc.sample);
- d->dc.sample = 0;
- d->dc.samples = 0;
- d->dc.alloc_samples = 0;
- } else {
+ if (same_string(d->dc.model, "manually added dive"))
+ free_samples(&d->dc);
+ else
appendTextToLog("Cannot change the duration on a dive that wasn't manually added");
- }
return true;
}
return false;
@@ -947,10 +943,7 @@ bool QMLManager::checkDepth(DiveObjectHelper *myDive, dive *d, QString depth)
d->maxdepth.mm = depthValue;
if (same_string(d->dc.model, "manually added dive")) {
d->dc.maxdepth.mm = d->maxdepth.mm;
- free(d->dc.sample);
- d->dc.sample = 0;
- d->dc.samples = 0;
- d->dc.alloc_samples = 0;
+ free_samples(&d->dc);
}
return true;
}