From be547081f22d7f5c37a6e4705fbf10d3ebd3b108 Mon Sep 17 00:00:00 2001 From: Felix Kauselmann Date: Mon, 30 Apr 2018 18:24:31 +0200 Subject: [PATCH] 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. --- .../server/controllers/v1/comiccontroller.cpp | 7 ++++--- .../server/controllers/v2/comiccontroller_v2.cpp | 16 +++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/YACReaderLibrary/server/controllers/v1/comiccontroller.cpp b/YACReaderLibrary/server/controllers/v1/comiccontroller.cpp index a01d510b..c523d689 100644 --- a/YACReaderLibrary/server/controllers/v1/comiccontroller.cpp +++ b/YACReaderLibrary/server/controllers/v1/comiccontroller.cpp @@ -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())); diff --git a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp index eca197d6..5e89fbf9 100644 --- a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp @@ -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";