From da1fba8b3278219a90619361812c0455f756bd2b Mon Sep 17 00:00:00 2001 From: Ed Gamble Date: Thu, 27 Sep 2018 09:20:24 -0700 Subject: [PATCH] CORE-66: In Core Ethereum, address memory management in EWM and BCS event handling. --- ethereum/bcs/BREthereumBCS.c | 12 ++++++++---- ethereum/bcs/BREthereumBCSEvent.c | 17 +++++++++++++++-- ethereum/ewm/BREthereumEWMClientEvent.c | 24 +++++++++++++++++++++--- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/ethereum/bcs/BREthereumBCS.c b/ethereum/bcs/BREthereumBCS.c index 9c13a8b0b..a867e30a1 100644 --- a/ethereum/bcs/BREthereumBCS.c +++ b/ethereum/bcs/BREthereumBCS.c @@ -117,8 +117,8 @@ bcsCreateInitializeBlocks (BREthereumBCS bcs, bcs->chainTail = bcs->chain; } - array_free(sortedBlocks); - array_free(blocks); + array_free (sortedBlocks); + array_free (blocks); } static void @@ -135,8 +135,10 @@ bcsCreateInitializeTransactions (BREthereumBCS bcs, TRANSACTION_STATUS_ERRORED == status.type || TRANSACTION_STATUS_PENDING == status.type); - bcsSignalTransaction(bcs, transaction); + bcsSignalTransaction (bcs, transaction); } + + array_free (transactions); } static void @@ -153,8 +155,10 @@ bcsCreateInitializeLogs (BREthereumBCS bcs, TRANSACTION_STATUS_ERRORED == status.type || TRANSACTION_STATUS_PENDING == status.type); - bcsSignalLog(bcs, log); + bcsSignalLog (bcs, log); } + + array_free (logs); } extern BREthereumBCS diff --git a/ethereum/bcs/BREthereumBCSEvent.c b/ethereum/bcs/BREthereumBCSEvent.c index 897e5f5b9..2c73e6031 100644 --- a/ethereum/bcs/BREthereumBCSEvent.c +++ b/ethereum/bcs/BREthereumBCSEvent.c @@ -188,10 +188,16 @@ bcsHandleTransactionDispatcher (BREventHandler ignore, bcsHandleTransaction(event->bcs, event->transaction); } +static void +bcsHandleTransactionDestroyer (BREthereumHandleTransactionEvent *event) { + transactionRelease(event->transaction); +} + static BREventType handleTransactionEventType = { "BCS: Handle Transaction Event", sizeof (BREthereumHandleTransactionEvent), - (BREventDispatcher) bcsHandleTransactionDispatcher + (BREventDispatcher) bcsHandleTransactionDispatcher, + (BREventDestroyer) bcsHandleTransactionDestroyer }; extern void @@ -219,10 +225,16 @@ bcsHandleLogDispatcher (BREventHandler ignore, event->log); } +static void +bcsHandleLogDestroyer (BREthereumHandleLogEvent *event) { + logRelease(event->log); +} + static BREventType handleLogEventType = { "BCS: Handle Log Event", sizeof (BREthereumHandleLogEvent), - (BREventDispatcher) bcsHandleLogDispatcher + (BREventDispatcher) bcsHandleLogDispatcher, + (BREventDestroyer) bcsHandleLogDestroyer }; extern void @@ -297,6 +309,7 @@ bcsSyncHandleProvisionDispatcher (BREventHandler ignore, static void bcsSyncHandleProvisionDestroyer (BREthereumHandleProvisionEvent *event) { + // syncRangeRelease (event->range); // provisionResultRelease(event->result); } diff --git a/ethereum/ewm/BREthereumEWMClientEvent.c b/ethereum/ewm/BREthereumEWMClientEvent.c index ce69038b5..0829f873e 100644 --- a/ethereum/ewm/BREthereumEWMClientEvent.c +++ b/ethereum/ewm/BREthereumEWMClientEvent.c @@ -467,10 +467,16 @@ ewmClientSignalAnnounceTransactionDispatcher (BREventHandler ignore, ewmClientHandleAnnounceTransaction(event->ewm, event->bundle, event->rid); } +static void +ewmClientSignalAnnounceTransactionDestroyer (BREthereumEWMClientAnnounceTransactionEvent *event) { + ewmClientAnnounceTransactionBundleRelease(event->bundle); +} + static BREventType ewmClientAnnounceTransactionEventType = { "EWM: Client Announce Transaction Event", sizeof (BREthereumEWMClientAnnounceTransactionEvent), - (BREventDispatcher) ewmClientSignalAnnounceTransactionDispatcher + (BREventDispatcher) ewmClientSignalAnnounceTransactionDispatcher, + (BREventDestroyer) ewmClientSignalAnnounceTransactionDestroyer }; extern void @@ -498,10 +504,16 @@ ewmClientSignalAnnounceLogDispatcher (BREventHandler ignore, ewmClientHandleAnnounceLog(event->ewm, event->bundle, event->rid); } +static void +ewmClientSignalAnnounceLogDestroyer (BREthereumEWMClientAnnounceLogEvent *event) { + ewmClientAnnounceLogBundleRelease(event->bundle); +} + static BREventType ewmClientAnnounceLogEventType = { "EWM: Client Announce Log Event", sizeof (BREthereumEWMClientAnnounceLogEvent), - (BREventDispatcher) ewmClientSignalAnnounceLogDispatcher + (BREventDispatcher) ewmClientSignalAnnounceLogDispatcher, + (BREventDestroyer) ewmClientSignalAnnounceLogDestroyer }; extern void @@ -529,10 +541,16 @@ ewmClientSignalAnnounceTokenDispatcher (BREventHandler ignore, ewmClientHandleAnnounceToken(event->ewm, event->bundle, event->rid); } +static void +ewmClientSignalAnnounceTokenDestroyer (BREthereumEWMClientAnnounceTokenEvent *event) { + ewmClientAnnounceTokenBundleRelease(event->bundle); +} + static BREventType ewmClientAnnounceTokenEventType = { "EWM: Client Announce Token Event", sizeof (BREthereumEWMClientAnnounceTokenEvent), - (BREventDispatcher) ewmClientSignalAnnounceTokenDispatcher + (BREventDispatcher) ewmClientSignalAnnounceTokenDispatcher, + (BREventDestroyer) ewmClientSignalAnnounceTokenDestroyer }; extern void