Copy picture struct for worker thread

This copies the picture struct when delegating image handling
to a worker thread to prevent a crashe when main thread
frees the picture upon selecting a different dive.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2016-03-16 00:29:28 +01:00 committed by Dirk Hohndel
parent 2368f3371b
commit 2639281354
5 changed files with 36 additions and 8 deletions

16
dive.c
View file

@ -2357,6 +2357,20 @@ static void free_pic(struct picture *picture)
}
}
// When handling pictures in different threads, we need to copy them so we don't
// run into problems when the main thread frees the picture.
struct picture *clone_picture(struct picture *src)
{
struct picture *dst;
dst = alloc_picture();
copy_pl(src, dst);
return dst;
}
static int same_sample(struct sample *a, struct sample *b)
{
if (a->time.seconds != b->time.seconds)
@ -3387,7 +3401,7 @@ void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
}
}
static void picture_free(struct picture *picture)
void picture_free(struct picture *picture)
{
if (!picture)
return;