mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-17 15:21:30 +02:00
free memory in onOutputSpent/Received() with monero_utils::free(blocks)
This commit is contained in:
@@ -152,5 +152,36 @@ namespace monero_utils
|
||||
CHECK_AND_ASSERT_MES(r, std::string(), "Failed to serialize rct signatures base");
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory of a block.
|
||||
*
|
||||
* @param block is the block to free
|
||||
*/
|
||||
static void free(shared_ptr<monero_block> block) {
|
||||
for (shared_ptr<monero_tx>& tx : block->m_txs) {
|
||||
tx->m_block.reset();
|
||||
monero_tx_wallet* tx_wallet = dynamic_cast<monero_tx_wallet*>(tx.get());
|
||||
if (tx_wallet != nullptr) {
|
||||
if (tx_wallet->m_outgoing_transfer != boost::none) tx_wallet->m_outgoing_transfer.get()->m_tx.reset();
|
||||
for (shared_ptr<monero_transfer> transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset();
|
||||
for (shared_ptr<monero_output> output : tx_wallet->m_outputs) output->m_tx.reset();
|
||||
for (shared_ptr<monero_output> input : tx_wallet->m_inputs) {
|
||||
input->m_key_image.reset();
|
||||
input->m_tx.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
block.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory of blocks.
|
||||
*
|
||||
* @param blocks are blocks to free
|
||||
*/
|
||||
static void free(vector<shared_ptr<monero_block>> blocks) {
|
||||
for (shared_ptr<monero_block>& block : blocks) monero_utils::free(block);
|
||||
}
|
||||
}
|
||||
#endif /* monero_utils_h */
|
||||
|
||||
@@ -731,6 +731,11 @@ namespace monero {
|
||||
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
|
||||
listener->on_output_received(*output);
|
||||
}
|
||||
|
||||
// free memory
|
||||
monero_utils::free(block);
|
||||
output.reset();
|
||||
tx.reset();
|
||||
}
|
||||
|
||||
void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx_in, uint64_t amount, const cryptonote::transaction& cn_tx_out, const cryptonote::subaddress_index& subaddr_index) {
|
||||
@@ -756,6 +761,11 @@ namespace monero {
|
||||
listener->on_output_spent(*output);
|
||||
}
|
||||
|
||||
// free memory
|
||||
monero_utils::free(block);
|
||||
output.reset();
|
||||
tx.reset();
|
||||
|
||||
// TODO **: to notify or not to notify?
|
||||
// std::string tx_hash = epee::string_tools::pod_to_hex(txid);
|
||||
// LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height
|
||||
|
||||
Reference in New Issue
Block a user