Fix memory leaks & data races in tests (#4772)
* Add a few pre-made sanitizer suppressions * Test Sanitization: Fix threading issues * Test Sanitization: Allow deletion of PubSub We still don't delete it in main code, but this allows us to try deleting it in tests. * Test Sanitization: Fix some memory leaks * fix gtest clang-tidy warning * const emojis test :-)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
template <typename T>
|
||||
class ReceivedMessage
|
||||
{
|
||||
mutable std::mutex mutex;
|
||||
|
||||
bool isSet{false};
|
||||
T t;
|
||||
|
||||
public:
|
||||
ReceivedMessage() = default;
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
return this->isSet;
|
||||
}
|
||||
|
||||
ReceivedMessage &operator=(const T &newT)
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
this->isSet = true;
|
||||
this->t = newT;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const T &otherT) const
|
||||
{
|
||||
std::unique_lock lock(this->mutex);
|
||||
|
||||
return this->t == otherT;
|
||||
}
|
||||
|
||||
const T *operator->() const
|
||||
{
|
||||
return &this->t;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user