From a2221567ab3ce3b7df40825ba41f0259bf6ea340 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Mon, 5 Oct 2020 10:53:44 +0200 Subject: [PATCH] Fix memory leaks in transaction_test_xa unit tests Cleanup the streaming applier created by xa_detach() and xa_replay(). --- test/transaction_test_xa.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/test/transaction_test_xa.cpp b/test/transaction_test_xa.cpp index 2fcead5..82106c4 100644 --- a/test/transaction_test_xa.cpp +++ b/test/transaction_test_xa.cpp @@ -66,7 +66,6 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_detach_commit_by_xid, cc1.xa_detach(); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted); - BOOST_REQUIRE(sc.find_streaming_applier(xid)); BOOST_REQUIRE(cc1.after_statement() == 0); cc2.start_transaction(wsrep::transaction_id(2)); @@ -74,6 +73,16 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_detach_commit_by_xid, BOOST_REQUIRE(cc2.client_state::commit_by_xid(xid) == 0); BOOST_REQUIRE(cc2.after_statement() == 0); BOOST_REQUIRE(sc.provider().commit_fragments() == 1); + + // xa_detach() creates a streaming applier, clean it up + wsrep::mock_high_priority_service* hps( + static_cast( + sc.find_streaming_applier(xid))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } BOOST_FIXTURE_TEST_CASE(transaction_xa_detach_rollback_by_xid, @@ -91,7 +100,6 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_detach_rollback_by_xid, cc1.xa_detach(); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted); - BOOST_REQUIRE(sc.find_streaming_applier(xid)); BOOST_REQUIRE(cc1.after_statement() == 0); cc2.start_transaction(wsrep::transaction_id(2)); @@ -99,6 +107,16 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_detach_rollback_by_xid, BOOST_REQUIRE(cc2.rollback_by_xid(xid) == 0); BOOST_REQUIRE(cc2.after_statement() == 0); BOOST_REQUIRE(sc.provider().rollback_fragments() == 1); + + // xa_detach() creates a streaming applier, clean it up + wsrep::mock_high_priority_service* hps( + static_cast( + sc.find_streaming_applier(xid))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } @@ -126,8 +144,16 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_replay, cc.sync_rollback_complete(); BOOST_REQUIRE(cc.unordered_replays() == 1); - BOOST_REQUIRE(sc.find_streaming_applier(sc.id(), - wsrep::transaction_id(1))); + + // xa_replay() createa a streaming applier, clean it up + wsrep::mock_high_priority_service* hps( + static_cast( + sc.find_streaming_applier(sc.id(), wsrep::transaction_id(1)))); + BOOST_REQUIRE(hps); + hps->rollback(wsrep::ws_handle(), wsrep::ws_meta()); + hps->after_apply(); + sc.stop_streaming_applier(sc.id(), wsrep::transaction_id(1)); + server_service.release_high_priority_service(hps); } //