Skip to content

Commit

Permalink
gui: PreviewGeneratorPdf: Guard cache lookup with mutex
Browse files Browse the repository at this point in the history
No guarantes the read-only lookup is thread-safe so better
just lock there too
  • Loading branch information
crtxcr committed Oct 22, 2022
1 parent 49a1a14 commit 1b1ab23
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gui/previewgeneratorpdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ static QMutex cacheMutex;

Poppler::Document *PreviewGeneratorPdf::document(QString path)
{
QMutexLocker locker(&cacheMutex);
if(documentcache.contains(path))
{
return documentcache.value(path);
}
locker.unlock();
Poppler::Document *result = Poppler::Document::load(path);
if(result == nullptr)
{
Expand All @@ -19,7 +21,7 @@ Poppler::Document *PreviewGeneratorPdf::document(QString path)
}
result->setRenderHint(Poppler::Document::TextAntialiasing);

QMutexLocker locker(&cacheMutex);
locker.relock();
documentcache.insert(path, result);
locker.unlock();
return result;
Expand Down

0 comments on commit 1b1ab23

Please sign in to comment.