From 2d481c3555e74c0a2c494288d96d4da23c275da2 Mon Sep 17 00:00:00 2001 From: CJ Cobb Date: Thu, 11 Feb 2021 17:23:41 -0500 Subject: [PATCH] fix accountTx ref counting --- reporting/ReportingBackend.cpp | 4 +++- reporting/ReportingBackend.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/reporting/ReportingBackend.cpp b/reporting/ReportingBackend.cpp index 9e22ade6..5b855d4f 100644 --- a/reporting/ReportingBackend.cpp +++ b/reporting/ReportingBackend.cpp @@ -241,7 +241,9 @@ flatMapWriteAccountTxCallback(CassFuture* fut, void* cbData) backend.throttleCv_.notify_all(); if (backend.numRequestsOutstanding_ == 0) backend.syncCv_.notify_all(); - delete &requestParams; + int remaining = --requestParams.refs; + if (remaining == 0) + delete &requestParams; } } void diff --git a/reporting/ReportingBackend.h b/reporting/ReportingBackend.h index 27326291..f9bf0e4e 100644 --- a/reporting/ReportingBackend.h +++ b/reporting/ReportingBackend.h @@ -1378,11 +1378,12 @@ public: AccountTransactionsData data; uint32_t currentRetries = 0; + std::atomic refs; WriteAccountTxCallbackData( CassandraFlatMapBackend const* f, AccountTransactionsData&& data) - : backend(f), data(std::move(data)) + : backend(f), data(std::move(data)), refs(data.accounts.size()) { } };