diff options
Diffstat (limited to 'net-p2p/ktorrent/files/ktorrent-5.1.1-scanfolder-memcorruption.patch')
-rw-r--r-- | net-p2p/ktorrent/files/ktorrent-5.1.1-scanfolder-memcorruption.patch | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/net-p2p/ktorrent/files/ktorrent-5.1.1-scanfolder-memcorruption.patch b/net-p2p/ktorrent/files/ktorrent-5.1.1-scanfolder-memcorruption.patch new file mode 100644 index 000000000000..4c41a6af11db --- /dev/null +++ b/net-p2p/ktorrent/files/ktorrent-5.1.1-scanfolder-memcorruption.patch @@ -0,0 +1,69 @@ +From 2d73d5f25a1a364a2115fb1d3262377f7fdf99cd Mon Sep 17 00:00:00 2001 +From: Valeriy Malov <jazzvoid@gmail.com> +Date: Wed, 5 Sep 2018 20:43:51 +0300 +Subject: Fix memory corruption in ScanFolder plugin + +Summary: +Reasoning behind this patch is kinda dubious because I don't fully understand what happens, but it shouldn't make the matters worse either + +Seems like deletion of KDirWatch objects from scan_folder in ~ScanThread(), after said QThread has been stopped, causes memory corruption. + +Preemptively deleting scan_folder contents before we stop the thread resolves this. + +also mark booleans shared across main thread and KDirWatch callbacks as atomic + +Test Plan: +Without this patch unloading ScanFolder plugin sometimes crashes ktorrent, including unloading on exit +Doesn't happen anymore with this patch + +Reviewers: stikonas + +Reviewed By: stikonas + +Differential Revision: https://phabricator.kde.org/D15265 +--- + plugins/scanfolder/scanthread.cpp | 5 +++++ + plugins/scanfolder/scanthread.h | 5 +++-- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/plugins/scanfolder/scanthread.cpp b/plugins/scanfolder/scanthread.cpp +index 0e62768..d7b13e0 100644 +--- a/plugins/scanfolder/scanthread.cpp ++++ b/plugins/scanfolder/scanthread.cpp +@@ -156,6 +156,11 @@ namespace kt + void ScanThread::stop() + { + stop_requested = true; ++ ++ // XXX seems like deleting KDirWatch object(s) created in scan_folders ++ // in destructor of this QThread after it has been stopped ++ // causes memory corruption, so we delete them early ++ scan_folders.clear(); + exit(); + wait(); + } +diff --git a/plugins/scanfolder/scanthread.h b/plugins/scanfolder/scanthread.h +index d13ca08..fb214a4 100644 +--- a/plugins/scanfolder/scanthread.h ++++ b/plugins/scanfolder/scanthread.h +@@ -29,6 +29,7 @@ + #include <util/ptrmap.h> + #include "scanfolder.h" + ++#include <atomic> + + class QDir; + +@@ -88,8 +89,8 @@ namespace kt + private: + QMutex mutex; + QStringList folders; +- bool stop_requested; +- bool recursive; ++ std::atomic<bool> stop_requested; ++ std::atomic<bool> recursive; + bt::PtrMap<QString, ScanFolder> scan_folders; + }; + +-- +cgit v0.11.2 |