Skip to content

Commit

Permalink
CORE-734: GEN Memory Issues #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Gamble committed Nov 7, 2019
1 parent 68ac889 commit 8595a3c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions Swift/BRCrypto/common/BRBlockChainDB.swift
Expand Up @@ -525,6 +525,7 @@ public class BlockChainDB {
]
default:
precondition(false);
return [:]
}
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/BRCryptoPrivate.h
Expand Up @@ -204,7 +204,7 @@ extern "C" {
extern BRCryptoTransfer
cryptoTransferCreateAsGEN (BRCryptoUnit unit,
BRCryptoUnit unitForFee,
BRGenericTransfer tid);
OwnershipGiven BRGenericTransfer tid);

private_extern BRTransaction *
cryptoTransferAsBTC (BRCryptoTransfer transfer);
Expand Down Expand Up @@ -464,7 +464,7 @@ extern "C" {

extern void
cryptoWalletManagerHandleTransferGEN (BRCryptoWalletManager cwm,
BRGenericTransfer transferGeneric);
OwnershipGiven BRGenericTransfer transferGeneric);

private_extern void
cryptoWalletManagerSetTransferStateGEN (BRCryptoWalletManager cwm,
Expand Down
12 changes: 11 additions & 1 deletion crypto/BRCryptoTransfer.c
Expand Up @@ -252,7 +252,7 @@ cryptoTransferCreateAsETH (BRCryptoUnit unit,
extern BRCryptoTransfer
cryptoTransferCreateAsGEN (BRCryptoUnit unit,
BRCryptoUnit unitForFee,
BRGenericTransfer tid) {
OwnershipGiven BRGenericTransfer tid) {
BRCryptoTransfer transfer = cryptoTransferCreateInternal (BLOCK_CHAIN_TYPE_GEN, unit, unitForFee);
transfer->u.gen = tid;

Expand All @@ -274,6 +274,16 @@ cryptoTransferRelease (BRCryptoTransfer transfer) {
cryptoTransferStateRelease (&transfer->state);
if (NULL != transfer->feeBasisEstimated) cryptoFeeBasisGive (transfer->feeBasisEstimated);

switch (transfer->type) {
case BLOCK_CHAIN_TYPE_BTC:
break;
case BLOCK_CHAIN_TYPE_ETH:
break;
case BLOCK_CHAIN_TYPE_GEN:
genTransferRelease(transfer->u.gen);
break;
}

pthread_mutex_destroy (&transfer->lock);

memset (transfer, 0, sizeof(*transfer));
Expand Down
8 changes: 6 additions & 2 deletions crypto/BRCryptoWalletManager.c
Expand Up @@ -286,6 +286,7 @@ cryptoWalletManagerCreate (BRCryptoCWMListener listener,
// TODO: A BRGenericTransfer must allow us to determine the Wallet (via a Currency).
cryptoWalletManagerHandleTransferGEN (cwm, transfers[index]);
}
array_free (transfers);

// Having added the transfers, get the wallet balance...
BRCryptoAmount balance = cryptoWalletGetBalance (cwm->wallet);
Expand Down Expand Up @@ -1169,7 +1170,7 @@ cryptoWalletManagerFindWalletAsGEN (BRCryptoWalletManager cwm,

extern void
cryptoWalletManagerHandleTransferGEN (BRCryptoWalletManager cwm,
BRGenericTransfer transferGeneric) {
OwnershipGiven BRGenericTransfer transferGeneric) {
// TODO: I don't think any locks are needed here...

// TODO: Determine the currency from `transferGeneric`
Expand All @@ -1184,7 +1185,7 @@ cryptoWalletManagerHandleTransferGEN (BRCryptoWalletManager cwm,
BRCryptoUnit unit = cryptoNetworkGetUnitAsBase (cwm->network, currency);
BRCryptoUnit unitForFee = cryptoNetworkGetUnitAsBase (cwm->network, currency);

// Create the generic transfer...
// Create the generic transfer... `transferGeneric` owned by `transfer`
transfer = cryptoTransferCreateAsGEN (unit, unitForFee, transferGeneric);

// Set the state
Expand Down Expand Up @@ -1237,6 +1238,9 @@ cryptoWalletManagerHandleTransferGEN (BRCryptoWalletManager cwm,
cryptoUnitGive(unitForFee);
cryptoUnitGive(unit);
}
else {
genTransferRelease (transferGeneric);
}

cryptoTransferGive(transfer);
cryptoWalletGive (wallet);
Expand Down
8 changes: 5 additions & 3 deletions generic/BRGenericManager.c
Expand Up @@ -509,7 +509,8 @@ genManagerPeriodicDispatcher (BREventHandler handler,

// 3) we'll update transactions if there are more blocks to examine
if (gwm->brdSync.begBlockNumber != gwm->brdSync.endBlockNumber) {
char *address = genAddressAsString (genManagerGetAccountAddress(gwm));
BRGenericAddress accountAddress = genManagerGetAccountAddress(gwm);
char *address = genAddressAsString (accountAddress);

// 3a) Save the current requestId
gwm->brdSync.rid = gwm->requestId;
Expand All @@ -536,8 +537,9 @@ genManagerPeriodicDispatcher (BREventHandler handler,
gwm->requestId++);
}

// TODO: Handle address
// free (address);

free (address);
genAddressRelease(accountAddress);

// 3c) Mark as not completed
gwm->brdSync.completed = 0;
Expand Down

0 comments on commit 8595a3c

Please sign in to comment.