summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/dive.c11
-rw-r--r--core/dive.h1
2 files changed, 10 insertions, 2 deletions
diff --git a/core/dive.c b/core/dive.c
index dd6edaa84..20981c48c 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -339,6 +339,14 @@ static void copy_pl(struct picture *sp, struct picture *dp)
dp->filename = copy_string(sp->filename);
}
+/* The first divecomputer is embedded in the dive structure. Free its data but not
+ * the structure itself. For all remainding dcs in the list, free data *and* structures. */
+void free_dive_dcs(struct divecomputer *dc)
+{
+ free_dc_contents(dc);
+ STRUCTURED_LIST_FREE(struct divecomputer, dc->next, free_dc);
+}
+
static void free_dive_structures(struct dive *d)
{
if (!d)
@@ -350,8 +358,7 @@ static void free_dive_structures(struct dive *d)
free(d->suit);
/* free tags, additional dive computers, and pictures */
taglist_free(d->tag_list);
- free_dc_contents(&d->dc);
- STRUCTURED_LIST_FREE(struct divecomputer, d->dc.next, free_dc);
+ free_dive_dcs(&d->dc);
STRUCTURED_LIST_FREE(struct picture, d->picture_list, free_picture);
for (int i = 0; i < MAX_CYLINDERS; i++)
free((void *)d->cylinder[i].type.description);
diff --git a/core/dive.h b/core/dive.h
index 5f525c013..87aa3e5fd 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -326,6 +326,7 @@ extern void utc_mkdate(timestamp_t, struct tm *tm);
extern struct dive *alloc_dive(void);
extern void free_dive(struct dive *);
+extern void free_dive_dcs(struct divecomputer *dc);
extern void record_dive_to_table(struct dive *dive, struct dive_table *table);
extern void record_dive(struct dive *dive);
extern void clear_dive(struct dive *dive);