mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-27 23:25:53 +00:00
Fix memory errors (#108)
* frees getUint64Tuple tuple iterator * explicitly create strand in synchronous()
This commit is contained in:
@@ -252,8 +252,9 @@ BackendInterface::fetchLedgerPage(
|
||||
std::vector<ripple::uint256> keys;
|
||||
while (keys.size() < limit)
|
||||
{
|
||||
ripple::uint256 const& curCursor =
|
||||
keys.size() ? keys.back() : cursor ? *cursor : firstKey;
|
||||
ripple::uint256 const& curCursor = keys.size() ? keys.back()
|
||||
: cursor ? *cursor
|
||||
: firstKey;
|
||||
auto succ = fetchSuccessorKey(curCursor, ledgerSequence, yield);
|
||||
|
||||
if (!succ)
|
||||
|
||||
@@ -37,18 +37,17 @@ retryOnTimeout(F func, size_t waitMs = 500)
|
||||
}
|
||||
}
|
||||
|
||||
// Please note, this function only works w/ non-void return type. Writes are
|
||||
// synchronous anyways, so
|
||||
template <class F>
|
||||
void
|
||||
synchronous(F&& f)
|
||||
{
|
||||
boost::asio::io_context ctx;
|
||||
boost::asio::io_context::strand strand(ctx);
|
||||
std::optional<boost::asio::io_context::work> work;
|
||||
|
||||
work.emplace(ctx);
|
||||
|
||||
boost::asio::spawn(ctx, [&f, &work](boost::asio::yield_context yield) {
|
||||
boost::asio::spawn(strand, [&f, &work](boost::asio::yield_context yield) {
|
||||
f(yield);
|
||||
|
||||
work.reset();
|
||||
@@ -218,7 +217,7 @@ public:
|
||||
hardFetchLedgerRange() const
|
||||
{
|
||||
std::optional<LedgerRange> range = {};
|
||||
synchronous([&](boost::asio::yield_context yield) {
|
||||
synchronous([&](boost::asio::yield_context& yield) {
|
||||
range = hardFetchLedgerRange(yield);
|
||||
});
|
||||
|
||||
|
||||
@@ -423,20 +423,32 @@ public:
|
||||
if (!row_)
|
||||
throw std::runtime_error(
|
||||
"CassandraResult::getInt64Tuple - no result");
|
||||
|
||||
CassValue const* tuple = cass_row_get_column(row_, curGetIndex_);
|
||||
CassIterator* tupleIter = cass_iterator_from_tuple(tuple);
|
||||
|
||||
if (!cass_iterator_next(tupleIter))
|
||||
{
|
||||
cass_iterator_free(tupleIter);
|
||||
throw std::runtime_error(
|
||||
"CassandraResult::getInt64Tuple - failed to iterate tuple");
|
||||
}
|
||||
|
||||
CassValue const* value = cass_iterator_get_value(tupleIter);
|
||||
std::int64_t first;
|
||||
cass_value_get_int64(value, &first);
|
||||
if (!cass_iterator_next(tupleIter))
|
||||
{
|
||||
cass_iterator_free(tupleIter);
|
||||
throw std::runtime_error(
|
||||
"CassandraResult::getInt64Tuple - failed to iterate tuple");
|
||||
}
|
||||
|
||||
value = cass_iterator_get_value(tupleIter);
|
||||
std::int64_t second;
|
||||
cass_value_get_int64(value, &second);
|
||||
cass_iterator_free(tupleIter);
|
||||
|
||||
++curGetIndex_;
|
||||
return {first, second};
|
||||
}
|
||||
|
||||
@@ -886,7 +886,7 @@ make_PgPool(boost::asio::io_context& ioc, boost::json::object const& config)
|
||||
auto ret = std::make_shared<PgPool>(ioc, configCopy);
|
||||
ret->setup();
|
||||
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
PgQuery pgQuery(ret);
|
||||
std::string query = "CREATE DATABASE " +
|
||||
std::string{config.at("database").as_string().c_str()};
|
||||
|
||||
@@ -141,7 +141,7 @@ ReportingETL::publishLedger(ripple::LedgerInfo const& lgrInfo)
|
||||
|
||||
std::vector<Backend::LedgerObject> diff;
|
||||
auto fetchDiffSynchronous = [&]() {
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
diff = backend_->fetchLedgerDiff(lgrInfo.seq, yield);
|
||||
});
|
||||
};
|
||||
@@ -156,13 +156,13 @@ ReportingETL::publishLedger(ripple::LedgerInfo const& lgrInfo)
|
||||
std::vector<Backend::TransactionAndMetadata> transactions = {};
|
||||
|
||||
auto fetchFeesSynchronous = [&]() {
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
fees = backend_->fetchFees(lgrInfo.seq, yield);
|
||||
});
|
||||
};
|
||||
|
||||
auto fetchTxSynchronous = [&]() {
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
transactions =
|
||||
backend_->fetchAllTransactionsInLedger(lgrInfo.seq, yield);
|
||||
});
|
||||
@@ -224,7 +224,7 @@ ReportingETL::publishLedger(
|
||||
{
|
||||
std::optional<ripple::LedgerInfo> lgr = {};
|
||||
auto fetchLedgerSynchronous = [&]() {
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
lgr =
|
||||
backend_->fetchLedgerBySequence(ledgerSequence, yield);
|
||||
});
|
||||
@@ -733,8 +733,10 @@ ReportingETL::runETLPipeline(uint32_t startSequence, int numExtractors)
|
||||
ioContext_.post([this, &minSequence]() {
|
||||
BOOST_LOG_TRIVIAL(info) << "Running online delete";
|
||||
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
backend_->doOnlineDelete(*onlineDeleteInterval_, yield);
|
||||
Backend::synchronous(
|
||||
[&](boost::asio::yield_context& yield) {
|
||||
backend_->doOnlineDelete(
|
||||
*onlineDeleteInterval_, yield);
|
||||
});
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Finished online delete";
|
||||
@@ -781,7 +783,7 @@ void
|
||||
ReportingETL::monitor()
|
||||
{
|
||||
std::optional<uint32_t> latestSequence = {};
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
latestSequence = backend_->fetchLatestLedgerSequence(yield);
|
||||
});
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ SubscriptionManager::pubTransaction(
|
||||
{
|
||||
ripple::STAmount ownerFunds;
|
||||
auto fetchFundsSynchronous = [&]() {
|
||||
Backend::synchronous([&](boost::asio::yield_context yield) {
|
||||
Backend::synchronous([&](boost::asio::yield_context& yield) {
|
||||
ownerFunds = RPC::accountFunds(
|
||||
*backend_, lgrInfo.seq, amount, account, yield);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user