diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index a7e007c81..b6d99be3a 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -265,7 +265,8 @@ void dpow_statemachinestart(void *ptr) void **ptrs = ptr; struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint; int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,src_or_dest,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime; - memset(&zero,0,sizeof(zero)); + int32_t bp_alloc = 0; + memset(&zero,0,sizeof(zero)); MoM = zero; srcprevtxid0 = destprevtxid0 = zero; srcprevvout0 = destprevvout0 = -1; @@ -297,7 +298,7 @@ void dpow_statemachinestart(void *ptr) } if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 ) { - bp = calloc(1,sizeof(*bp)); + bp = calloc(1, sizeof(*bp)); bp_alloc = 1; //printf("allocate bp for %s ht.%d -> %s\n",src->symbol,checkpoint.blockhash.height,dest->symbol); Numallocated++; bp->MoM = MoM; @@ -596,6 +597,9 @@ void dpow_statemachinestart(void *ptr) dp->ratifying -= bp->isratify; // dp->blocks[bp->height] = 0; bp->state = 0xffffffff; + + // heap corruption detected? + if (bp_alloc) free(bp); free(ptr); }