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@merlins.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2013-02-06 20:17:30 +11:00 committed by Dirk Hohndel
parent a1ef8e5502
commit 50170e0cf3

View file

@ -420,7 +420,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dc_parser_destroy(parser);
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);