| Index: test/FilterEngine.cpp |
| diff --git a/test/FilterEngine.cpp b/test/FilterEngine.cpp |
| index 177c0c7f2147850c3d846786858b9817c14155b3..c1c34f36231c207ea2d6ca09e3b4a24ab3a80ba9 100644 |
| --- a/test/FilterEngine.cpp |
| +++ b/test/FilterEngine.cpp |
| @@ -16,6 +16,8 @@ |
| */ |
| #include "BaseJsTest.h" |
| +#include <thread> |
| +#include <chrono> |
| namespace |
| { |
| @@ -533,3 +535,27 @@ TEST_F(FilterEngineTest, ElemhideWhitelisting) |
| "http://example.co.uk", |
| documentUrls1)); |
| } |
| + |
| +TEST(NewFilterEngineTest, MemoryLeak_NoCircularReferences) |
| +{ |
| + std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine; |
| + { |
| + auto jsEngine = AdblockPlus::JsEngine::New(); |
| + weakJsEngine = jsEngine; |
| + jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); |
| + jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest())); |
| + jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem())); |
| + auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); |
| + } |
| + { |
| + // It's a hack to figure current race condition out (better than nothing): |
| + // IO or timer thread still can aquire a strong reference to JsEngine right |
| + // before destroying filterEngine holding JsEngine and keep it for some |
| + // time, so here we need to give it a reasonable amount of time to finish |
| + // the current operation. |
| + uint16_t attempts = 10; |
| + while (attempts-- > 0 && weakJsEngine.lock()) |
| + std::this_thread::sleep_for(std::chrono::milliseconds(500)); |
| + } |
| + EXPECT_FALSE(weakJsEngine.lock()); |
| +} |