Commit 2819a880 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Make sure old singleton doesn't get reported as leak if make_mock is used

Differential Revision: D9499697

fbshipit-source-id: b04e9e0d1bf4abf1b5ff497cefbc26da0176eaa2
parent afe40e06
...@@ -136,6 +136,7 @@ ...@@ -136,6 +136,7 @@
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <functional> #include <functional>
#include <list>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>
...@@ -703,6 +704,10 @@ class LeakySingleton { ...@@ -703,6 +704,10 @@ class LeakySingleton {
} }
auto& entry = entryInstance(); auto& entry = entryInstance();
if (entry.ptr) {
// Make sure existing pointer doesn't get reported as a leak by LSAN.
entry.leakedPtrs.push_back(std::exchange(entry.ptr, nullptr));
}
entry.createFunc = createFunc; entry.createFunc = createFunc;
entry.state = State::Dead; entry.state = State::Dead;
} }
...@@ -720,6 +725,7 @@ class LeakySingleton { ...@@ -720,6 +725,7 @@ class LeakySingleton {
CreateFunc createFunc; CreateFunc createFunc;
std::mutex mutex; std::mutex mutex;
detail::TypeDescriptor type_{typeid(T), typeid(Tag)}; detail::TypeDescriptor type_{typeid(T), typeid(Tag)};
std::list<T*> leakedPtrs;
}; };
static Entry& entryInstance() { static Entry& entryInstance() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment