From 1ac2c314deafdea24a877caee4e44e1fcbeb29be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20G=C3=B6dderz?= Date: Fri, 29 Mar 2019 16:00:53 +0100 Subject: [PATCH] Fixed several ASan errors in the catch tests (#8624) --- arangod/Aql/AqlItemBlockManager.h | 2 +- tests/Aql/ExecutionBlockImplTest.cpp | 2 ++ tests/Aql/SingleRowFetcherTest.cpp | 4 +++- tests/Graph/ConstantWeightShortestPathFinder.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arangod/Aql/AqlItemBlockManager.h b/arangod/Aql/AqlItemBlockManager.h index 7c8c8fc4c8..d7bf34c123 100644 --- a/arangod/Aql/AqlItemBlockManager.h +++ b/arangod/Aql/AqlItemBlockManager.h @@ -48,7 +48,7 @@ class AqlItemBlockManager { TEST_VIRTUAL AqlItemBlock* requestBlock(size_t nrItems, RegisterId nrRegs); /// @brief return a block to the manager - void returnBlock(AqlItemBlock*& block) noexcept; + TEST_VIRTUAL void returnBlock(AqlItemBlock*& block) noexcept; /// @brief return a block to the manager void returnBlock(std::unique_ptr block) noexcept { diff --git a/tests/Aql/ExecutionBlockImplTest.cpp b/tests/Aql/ExecutionBlockImplTest.cpp index 6d69ee3e7e..332b9641b0 100644 --- a/tests/Aql/ExecutionBlockImplTest.cpp +++ b/tests/Aql/ExecutionBlockImplTest.cpp @@ -85,6 +85,8 @@ SCENARIO("ExecutionBlockImpl", "[AQL][EXECUTOR][EXECBLOCKIMPL]") { fakeit::When(Method(mockEngine, itemBlockManager)).AlwaysReturn(blockManager); fakeit::When(Method(mockEngine, getQuery)).AlwaysReturn(&query); + fakeit::When(OverloadedMethod(mockBlockManager, returnBlock, void(AqlItemBlock*&))) + .AlwaysDo([&](AqlItemBlock*& block) -> void { delete block; block = nullptr; }); fakeit::When(ConstOverloadedMethod(mockQuery, queryOptions, QueryOptions const&())) .AlwaysDo([&]() -> QueryOptions const& { return lqueryOptions; }); fakeit::When(OverloadedMethod(mockQuery, queryOptions, QueryOptions & ())) diff --git a/tests/Aql/SingleRowFetcherTest.cpp b/tests/Aql/SingleRowFetcherTest.cpp index b076a98622..b21e5c6529 100644 --- a/tests/Aql/SingleRowFetcherTest.cpp +++ b/tests/Aql/SingleRowFetcherTest.cpp @@ -56,7 +56,6 @@ namespace aql { SCENARIO("SingleRowFetcher", "[AQL][EXECUTOR][FETCHER]") { ResourceMonitor monitor; ExecutionState state; - InputAqlItemRow row{CreateInvalidInputRowHint{}}; /* * A hopefully temporary hack. Use TEMPLATE_TEST_CASE instead when it's @@ -82,6 +81,7 @@ SCENARIO("SingleRowFetcher", "[AQL][EXECUTOR][FETCHER]") { GIVEN(std::string{"there are no blocks upstream, passBlocksThrough="} + std::string{passBlocksThrough}) { VPackBuilder input; BlockFetcherMock blockFetcherMock{monitor, 0}; + InputAqlItemRow row{CreateInvalidInputRowHint{}}; WHEN("the producer does not wait") { blockFetcherMock.shouldReturn(ExecutionState::DONE, nullptr); @@ -132,6 +132,7 @@ GIVEN(std::string{ std::string{passBlocksThrough}) { VPackBuilder input; BlockFetcherMock blockFetcherMock{monitor, 1}; + InputAqlItemRow row{CreateInvalidInputRowHint{}}; std::unique_ptr block = buildBlock<1>(&monitor, {{42}}); @@ -251,6 +252,7 @@ GIVEN(std::string{ GIVEN(std::string{"there are multiple blocks upstream, passBlocksThrough="} + std::string{passBlocksThrough}) { BlockFetcherMock blockFetcherMock{monitor, 1}; + InputAqlItemRow row{CreateInvalidInputRowHint{}}; // three 1-column matrices with 3, 2 and 1 rows, respectively std::unique_ptr block1 = buildBlock<1>(&monitor, {{{1}}, {{2}}, {{3}}}), diff --git a/tests/Graph/ConstantWeightShortestPathFinder.cpp b/tests/Graph/ConstantWeightShortestPathFinder.cpp index 4ad11c5747..b1d005ab20 100644 --- a/tests/Graph/ConstantWeightShortestPathFinder.cpp +++ b/tests/Graph/ConstantWeightShortestPathFinder.cpp @@ -317,7 +317,8 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") { if (result.length() != vertices.size()) return false; for (size_t i = 0; i < result.length(); i++) { - auto vert = result.vertexToAqlValue(spo->cache(), i); + AqlValue vert = result.vertexToAqlValue(spo->cache(), i); + AqlValueGuard guard{vert, true}; if (!vert.slice().get(StaticStrings::KeyString).isEqualString(vertices.at(i))) { LOG_DEVEL << "expected vertex " << vertices.at(i) << " but found " << vert.slice().get(StaticStrings::KeyString).toString(); @@ -328,7 +329,8 @@ TEST_CASE("ConstantWeightShortestPathFinder", "[graph]") { // First edge is by convention null CHECK((result.edgeToAqlValue(spo->cache(), 0).isNull(true))); for (size_t i = 1; i < result.length(); i++) { - auto edge = result.edgeToAqlValue(spo->cache(), i); + AqlValue edge = result.edgeToAqlValue(spo->cache(), i); + AqlValueGuard guard{edge, true}; if (!edge.slice().get(StaticStrings::FromString).isEqualString(edges.at(i).first) || !edge.slice().get(StaticStrings::ToString).isEqualString(edges.at(i).second)) { LOG_DEVEL << "expected edge " << edges.at(i).first << " -> "