[PATCH 3/2] Fix "prefer downloaded" dive sample merging case
Linus Torvalds
torvalds at linux-foundation.org
Fri Nov 23 22:02:18 PST 2012
From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Fri, 23 Nov 2012 19:58:00 -1000
Subject: [PATCH 3/2] Fix "prefer downloaded" dive sample merging case
When we have a preferred dive computer that overrides old information
when merging two dives, we just copy the dive computer data over.
However, we need to clear the source of the dive computer data so that
we then don't free the sample data when that old source of the newly
merged dive gets free'd.
This fixes a memory scribble (and likely SIGSEGV) for the "prefer
downloaded" case.
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
I didn't actually test this with a real dive computer download, I just
forced it with an xml file read. I'm lazy, and have already packed away
my dive computer download cables.
The SIGSEGV is definitely true, though.
dive.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/dive.c b/dive.c
index 698bd00e9c94..d69aee3559d2 100644
--- a/dive.c
+++ b/dive.c
@@ -1103,6 +1103,13 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, gboolean pr
merge_equipment(res, a, b);
if (dl) {
res->dc = dl->dc;
+ /*
+ * Since we copied the events and samples,
+ * we can't free them from the source when
+ * we free it - so make sure the source
+ * dive computer data is cleared out.
+ */
+ memset(&dl->dc, 0, sizeof(dl->dc));
} else {
merge_events(&res->dc, &a->dc, &b->dc, offset);
merge_samples(&res->dc, &a->dc, &b->dc, offset);
--
1.8.0
More information about the subsurface
mailing list