From 9f8a3553ba7e6c3ce5c9e378d77d3e16d7ce6daf Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Thu, 16 Jan 2020 12:52:12 +0100 Subject: [PATCH] Avoid deadlock in FairMQChannel operator=, handle self-assignment --- fairmq/FairMQChannel.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fairmq/FairMQChannel.cxx b/fairmq/FairMQChannel.cxx index 82f3b2ec..38d7c133 100644 --- a/fairmq/FairMQChannel.cxx +++ b/fairmq/FairMQChannel.cxx @@ -133,9 +133,15 @@ FairMQChannel::FairMQChannel(const FairMQChannel& chan, const string& newName) FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan) { + if (this == &chan) { + return *this; + } + { - lock_guard lock1(fMtx); - lock_guard lock2(chan.fMtx); + // TODO: replace this with std::scoped_lock (c++17) + lock(fMtx, chan.fMtx); + lock_guard lock1(fMtx, adopt_lock); + lock_guard lock2(chan.fMtx, adopt_lock); fTransportFactory = nullptr; fTransportType = chan.fTransportType;