Fix huge memleak in server code caused by thread pingpong fix.

Stopped QThreads don't process events, so cleanup signals get lost.
Prevent this from happening by keeping the threads alive and the comic
inside the thread (as we already do in the viewer). Cleanup happens by
connecting the comic's destroyed() signal to the thread's quit() slot.
This commit is contained in:
Felix Kauselmann 2018-04-30 18:24:31 +02:00 committed by Luis Ángel San Martín
parent cc71f419cc
commit be547081f2
2 changed files with 11 additions and 12 deletions

View File

@ -57,9 +57,10 @@ void ComicController::service(HttpRequest &request, HttpResponse &response)
comicFile->moveToThread(thread);
connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
//connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
//connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
//connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
connect(comicFile, SIGNAL(destroyed()), thread, SLOT(quit()));
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

View File

@ -53,23 +53,21 @@ void ComicControllerV2::service(HttpRequest &request, HttpResponse &response)
Comic *comicFile = FactoryComic::newComic(libraries.getPath(libraryId) + comic.path);
if (comicFile != nullptr) {
QThread *thread = nullptr;
thread = new QThread();
if (comicFile != NULL) {
QThread *thread = new QThread();
comicFile->moveToThread(thread);
connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
//connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit()));
//connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit()));
//connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit()));
connect(comicFile, SIGNAL(destroyed()), thread, SLOT(quit()));
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
comicFile->load(libraries.getPath(libraryId) + comic.path);
if (thread != nullptr)
thread->start();
thread->start();
if (remoteComic) {
QLOG_TRACE() << "remote comic requested";