Skip to content
Snippets Groups Projects
Commit a4f2e6ef authored by Adrien Béraud's avatar Adrien Béraud
Browse files

tests: avoid use-after-free in proxytester

parent 60831ee8
No related branches found
No related tags found
No related merge requests found
...@@ -160,20 +160,25 @@ DhtProxyTester::testResubscribeGetValues() { ...@@ -160,20 +160,25 @@ DhtProxyTester::testResubscribeGetValues() {
// For the second subscribe, the proxy will return the value in the body // For the second subscribe, the proxy will return the value in the body
auto values = std::vector<dht::Blob>(); auto values = std::vector<dht::Blob>();
nodeClient->listen(key, [&](const std::vector<std::shared_ptr<dht::Value>>& v, bool) { auto ftoken = nodeClient->listen(key, [&](const std::vector<std::shared_ptr<dht::Value>>& v, bool expired) {
for (const auto& value : v) if (not expired) {
values.emplace_back(value->data); std::lock_guard<std::mutex> lk(cv_m);
done = true; for (const auto& value : v)
values.emplace_back(value->data);
done = true;
}
cv.notify_all(); cv.notify_all();
return true; return true;
}); });
cv.wait_for(lk, std::chrono::seconds(10), [&]{ return done; }); cv.wait_for(lk, std::chrono::seconds(10), [&]{ return done; });
auto token = ftoken.get();
CPPUNIT_ASSERT(token);
nodeClient->cancelListen(key, token);
done = false; done = false;
// Here values should still contains 1 values // Here values should still contains 1 values
CPPUNIT_ASSERT_EQUAL(static_cast<int>(values.size()), 1); CPPUNIT_ASSERT_EQUAL((size_t)1u, values.size());
CPPUNIT_ASSERT(values.front() == firstVal_data); CPPUNIT_ASSERT(firstVal_data == values.front());
} }
} // namespace test } // namespace test
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment