summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-19 11:41:09 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-08-19 15:06:39 -0500
commit77f9bf06fded941aeff049cf5d3c0c3f2785d011 (patch)
tree2aba8de2c7e0af36a37bd3f0938da19e4e5ff733
parent6ed189f32c466f99167ab6657264a45da4b56e8e (diff)
downloadsubsurface-77f9bf06fded941aeff049cf5d3c0c3f2785d011.tar.gz
Planner: correctly free divedatapoints
Simply setting the pointer to NULL leaks memory. And that C++ recursive two function implementation... oh boy. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--planner.c6
-rw-r--r--planner.h1
-rw-r--r--qt-ui/diveplanner.cpp18
-rw-r--r--qt-ui/diveplanner.h1
4 files changed, 10 insertions, 16 deletions
diff --git a/planner.c b/planner.c
index ea180fb0a..f986af48b 100644
--- a/planner.c
+++ b/planner.c
@@ -348,13 +348,17 @@ gas_error_exit:
return;
}
-void free_dps(struct divedatapoint *dp)
+void free_dps(struct diveplan *diveplan)
{
+ if (!diveplan)
+ return;
+ struct divedatapoint *dp = diveplan->dp;
while (dp) {
struct divedatapoint *ndp = dp->next;
free(dp);
dp = ndp;
}
+ diveplan->dp = NULL;
}
struct divedatapoint *create_dp(int time_incr, int depth, struct gasmix gasmix, int po2)
diff --git a/planner.h b/planner.h
index a737f26c6..b1e37d5cb 100644
--- a/planner.h
+++ b/planner.h
@@ -20,6 +20,7 @@ extern void get_gas_at_time(struct dive *dive, struct divecomputer *dc, duration
extern int get_gasidx(struct dive *dive, struct gasmix *mix);
extern bool diveplan_empty(struct diveplan *diveplan);
+extern void free_dps(struct diveplan *diveplan);
extern struct dive *planned_dive;
extern char *cache_data;
extern const char *disclaimer;
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 6a6f2d6c3..999850183 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1000,7 +1000,7 @@ void DivePlannerPointsModel::cancelPlan()
}
}
setPlanMode(NOTHING);
- diveplan.dp = NULL;
+ free_dps(&diveplan);
emit planCanceled();
}
@@ -1089,7 +1089,7 @@ void DivePlannerPointsModel::clear()
void DivePlannerPointsModel::createTemporaryPlan()
{
// Get the user-input and calculate the dive info
- diveplan.dp = NULL;
+ free_dps(&diveplan);
int lastIndex = -1;
for (int i = 0; i < rowCount(); i++) {
divedatapoint p = at(i);
@@ -1137,17 +1137,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
void DivePlannerPointsModel::deleteTemporaryPlan()
{
- deleteTemporaryPlan(diveplan.dp);
- diveplan.dp = NULL;
-}
-
-void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
-{
- if (!dp)
- return;
-
- deleteTemporaryPlan(dp->next);
- free(dp);
+ free_dps(&diveplan);
}
void DivePlannerPointsModel::createPlan()
@@ -1166,7 +1156,7 @@ void DivePlannerPointsModel::createPlan()
// Remove and clean the diveplan, so we don't delete
// the dive by mistake.
- diveplan.dp = NULL;
+ free_dps(&diveplan);
setPlanMode(NOTHING);
planCreated();
}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 468893bba..da2f6526b 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -101,7 +101,6 @@ private:
Mode mode;
bool recalc;
QVector<divedatapoint> divepoints;
- void deleteTemporaryPlan(struct divedatapoint *dp);
QVector<sample> backupSamples; // For editing added dives.
QVector<QPair<int, int> > oldGases;
QDateTime startTime;