From 9bb6adc036f743746501d67009e4ee0b60b8c8cb Mon Sep 17 00:00:00 2001 From: Konrad Date: Mon, 1 Jan 2018 23:27:46 +0100 Subject: [PATCH] Added in Libresapi: Missing mutex locking in TransfersHandler --- libresapi/src/api/TransfersHandler.cpp | 5 +++-- libresapi/src/api/TransfersHandler.h | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libresapi/src/api/TransfersHandler.cpp b/libresapi/src/api/TransfersHandler.cpp index ccc6310b2..83b0039b7 100644 --- a/libresapi/src/api/TransfersHandler.cpp +++ b/libresapi/src/api/TransfersHandler.cpp @@ -8,7 +8,8 @@ namespace resource_api TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers, RsNotify* notify): - mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0), mNotify(notify) + mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0), mNotify(notify), + mMtx("TransfersHandler") { addResourceHandler("*", this, &TransfersHandler::handleWildcard); addResourceHandler("downloads", this, &TransfersHandler::handleDownloads); @@ -27,9 +28,9 @@ TransfersHandler::~TransfersHandler() void TransfersHandler::notifyListChange(int list, int /* type */) { - //RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ if(list == NOTIFY_LIST_TRANSFERLIST) { + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->discardToken(mStateToken); mStateToken = mStateTokenServer->getNewToken(); } diff --git a/libresapi/src/api/TransfersHandler.h b/libresapi/src/api/TransfersHandler.h index 0caf6acc6..0db387073 100644 --- a/libresapi/src/api/TransfersHandler.h +++ b/libresapi/src/api/TransfersHandler.h @@ -16,6 +16,8 @@ public: TransfersHandler(StateTokenServer* sts, RsFiles* files, RsPeers *peers, RsNotify* notify); virtual ~TransfersHandler(); + // from NotifyClient + // may be called from foreign thread virtual void notifyListChange(int list, int type); // from Tickable virtual void tick(); @@ -30,6 +32,7 @@ private: RsPeers* mRsPeers; RsNotify* mNotify; + RsMutex mMtx; StateToken mStateToken; time_t mLastUpdateTS;