diff options
author | Robert C. Helling <helling@atdotde.de> | 2016-03-15 21:31:59 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-03-16 07:46:28 -0700 |
commit | 8a59d78faa4792934a11a774c9dffcd85f0c3340 (patch) | |
tree | 5d38fc9d40712e2314759ff05ff0c0b58145fee6 /subsurface-core/qthelper.cpp | |
parent | 3c7e14a18fdc2ee9590e591afe4761a2d93881e7 (diff) | |
download | subsurface-8a59d78faa4792934a11a774c9dffcd85f0c3340.tar.gz |
When handing off a picture to a worker thread, copy it first
as otherwise we crash when the picture is freed before the
worker thread (to load from the net or to compute hashes)
is finished
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core/qthelper.cpp')
-rw-r--r-- | subsurface-core/qthelper.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index 7c67e0993..b3891298a 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -1108,11 +1108,14 @@ QString fileFromHash(char *hash) return localFilenameOf[QByteArray::fromHex(hash)]; } +// This needs to operate on a copy of picture as it frees it after finishing! void updateHash(struct picture *picture) { QByteArray hash = hashFile(fileFromHash(picture->hash)); learnHash(picture, hash); + picture_free(picture); } +// This needs to operate on a copy of picture as it frees it after finishing! void hashPicture(struct picture *picture) { char *oldHash = copy_string(picture->hash); @@ -1120,13 +1123,14 @@ void hashPicture(struct picture *picture) if (!same_string(picture->hash, "") && !same_string(picture->hash, oldHash)) mark_divelist_changed((true)); free(oldHash); + picture_free(picture); } extern "C" void cache_picture(struct picture *picture) { QString filename = picture->filename; if (!hashOf.contains(filename)) - QtConcurrent::run(hashPicture, picture); + QtConcurrent::run(hashPicture, clone_picture(picture)); } void learnImages(const QDir dir, int max_recursions) |