[PATCH] Don't re-use the dive computer model string for all downloaded dives

Linus Torvalds torvalds at linux-foundation.org
Wed Feb 6 01:23:33 PST 2013

From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Wed, 6 Feb 2013 20:17:30 +1100
Subject: [PATCH] Don't re-use the dive computer model string for all downloaded dives

When we download dives with libdivecomputer, we create this strdup'ed
name of the model information, but we then re-use that (single) strdup
allocation for every dive we download.  This works fine *until* you
start freeing those dives (possibly directly after the download because
they are redundant), at which point things go to hell in a handbasket,
since there is just the one allocation for all the different dives.

Fix by just doing another strdup() at the point where we assign the
model information to the dive computer.

Reported-by: Marc Merlin <marc at merlins.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
 libdivecomputer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libdivecomputer.c b/libdivecomputer.c
index d41c27b29c0b..f4f82fb8b3fb 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -420,7 +420,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
 		return rc;
-	dive->dc.model = devdata->model;
+	dive->dc.model = strdup(devdata->model);
 	dive->dc.deviceid = devdata->deviceid;
 	dive->dc.diveid = calculate_diveid(fingerprint, fsize);

More information about the subsurface mailing list