[PATCH 1/2] Make 'clear_dive()' free the primary dive computer data properly
Linus Torvalds
torvalds at linux-foundation.org
Tue May 31 10:10:51 PDT 2016
From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Mon, 11 Apr 2016 14:25:03 -0700
Subject: [PATCH 1/2] Make 'clear_dive()' free the primary dive computer data properly
Our primary dive computer really is special, not just because it's the
first one: it's directly embedded in the "struct dive", and so if you
just walk the divecomputer list, you'll miss it, because it's not _on_
the list, it is the very head _of_ the list.
We had that bug in copy_dive(), and it turns out we have it in
clear_dive() too: clear_dive() would free all the dive computers on the
list, but not the actual primary one.
This is a minor memory leak, no more, so it's not exactly critial, but
let's just do it right.
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
core/dive.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/core/dive.c b/core/dive.c
index 20ab2e5d6113..29198afd6e8b 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -364,6 +364,7 @@ struct dive *alloc_dive(void)
}
static void free_dc(struct divecomputer *dc);
+static void free_dc_contents(struct divecomputer *dc);
static void free_pic(struct picture *picture);
/* this is very different from the copy_divecomputer later in this file;
@@ -432,6 +433,7 @@ void clear_dive(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);
STRUCTURED_LIST_FREE(struct picture, d->picture_list, free_pic);
for (int i = 0; i < MAX_CYLINDERS; i++)
@@ -2479,11 +2481,16 @@ void free_events(struct event *ev)
}
}
-static void free_dc(struct divecomputer *dc)
+static void free_dc_contents(struct divecomputer *dc)
{
free(dc->sample);
free((void *)dc->model);
free_events(dc->events);
+}
+
+static void free_dc(struct divecomputer *dc)
+{
+ free_dc_contents(dc);
free(dc);
}
--
2.9.0.rc0.21.g7777322
More information about the subsurface
mailing list