diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 9b1c792f0..7fb4afd16 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -373,7 +373,7 @@ struct iguana_ramchain_hdr struct iguana_ramchain { - struct iguana_ramchain_hdr H; bits256 lasthash2; uint64_t datasize; + struct iguana_ramchain_hdr H; bits256 lasthash2; uint64_t datasize,allocatedA,allocatedU; uint32_t numblocks:31,expanded:1,pkind,externalind,height,numXspends; struct iguana_kvitem *txids,*pkhashes; struct OS_memspace *hashmem; long filesize,sigsfilesize,debitsfilesize,lastspendsfilesize; diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index c81fac535..32457c7e4 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -648,8 +648,16 @@ void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramch { if ( ramchain != 0 && ramchain->H.data != 0 ) { - ramchain->A = calloc(sizeof(*ramchain->A),ramchain->H.data->numpkinds + 16); - ramchain->Uextras = calloc(sizeof(*ramchain->Uextras),ramchain->H.data->numunspents + 16); + if ( ramchain->allocatedA == 0 ) + { + ramchain->A = calloc(sizeof(*ramchain->A),ramchain->H.data->numpkinds + 16); + ramchain->allocatedA = sizeof(*ramchain->A) * ramchain->H.data->numpkinds; + } + if ( ramchain->allocatedU == 0 ) + { + ramchain->Uextras = calloc(sizeof(*ramchain->Uextras),ramchain->H.data->numunspents + 16); + ramchain->allocatedU = sizeof(*ramchain->Uextras) * ramchain->H.data->numunspents; + } if ( ramchain->debitsfileptr != 0 ) { memcpy(ramchain->A,(void *)((long)ramchain->debitsfileptr + sizeof(int32_t) + sizeof(bits256)),sizeof(*ramchain->A) * ramchain->H.data->numpkinds); @@ -770,9 +778,17 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu if ( (bp= coin->bundles[hdrsi]) == 0 ) { if ( bp->ramchain.A != 0 ) + { free(bp->ramchain.A); + bp->ramchain.A = 0; + bp->ramchain.allocatedA = 0; + } if ( bp->ramchain.Uextras != 0 ) + { free(bp->ramchain.Uextras); + bp->ramchain.Uextras = 0; + bp->ramchain.allocatedU = 0; + } if ( iguana_mapvolatiles(coin,&bp->ramchain) != 0 ) printf("error mapping bundle.[%d]\n",hdrsi); }