From c2a5b849180e6eedc302d1ef9c99d40cb47d0b47 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 8 Mar 2019 12:45:52 +0800 Subject: [PATCH] Try to fix memleak! --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_fsm.c | 15 ++++++++++++--- iguana/iguana_notary.c | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 81812c3a9..fd2dfea68 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -115,7 +115,7 @@ struct dpow_block uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2]; struct dpow_recvdata recv[64]; struct dpow_entry notaries[DPOW_MAXRELAYS]; - uint32_t MoMdepth,state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc,lastnanosend; + uint32_t MoMdepth,state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc,lastnanosend,finished; int32_t rawratifiedlens[2],height,numnotaries,numerrors,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS]; int8_t myind,bestk,ratifybestk,pendingbestk,pendingratifybestk,matches,bestmatches; cJSON *ratified; diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index ff4fa6d6b..cd276a5d6 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -284,6 +284,7 @@ void dpow_statemachinestart(void *ptr) if ( src == 0 || dest == 0 ) { printf("null coin ptr? (%s %p or %s %p)\n",dp->symbol,src,dp->dest,dest); + bp->finished = 0xffffffff; free(ptr); return; } @@ -320,6 +321,7 @@ void dpow_statemachinestart(void *ptr) if ( numratified > 64 ) { fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified); + bp->finished = 0xffffffff; free(ptr); free_json(ratified); return; @@ -381,6 +383,7 @@ void dpow_statemachinestart(void *ptr) if ( dp->ratifying != 0 && bp->isratify == 0 ) { printf("skip notarization ht.%d when ratifying\n",bp->height); + bp->finished = 0xffffffff; free(ptr); return; } @@ -430,6 +433,7 @@ void dpow_statemachinestart(void *ptr) for (i=0; i<33; i++) printf("%02x",dp->minerkey33[i]); printf(" statemachinestart this node %s %s is not official notary numnotaries.%d kmdht.%d bpht.%d\n",srcaddr,destaddr,bp->numnotaries,kmdheight,bp->height); + bp->finished = 0xffffffff; free(ptr); dp->ratifying -= bp->isratify; exit(-1); @@ -440,6 +444,7 @@ void dpow_statemachinestart(void *ptr) else { printf("statemachinestart no kmdheight.%d\n",kmdheight); + bp->finished = 0xffffffff; free(ptr); dp->ratifying -= bp->isratify; return; @@ -455,6 +460,7 @@ void dpow_statemachinestart(void *ptr) printf("%02x",bp->ratified_pubkeys[0][i]); printf(" new, cant change notary0\n"); dp->ratifying -= bp->isratify; + bp->finished = 0xffffffff; free(ptr); return; } @@ -529,8 +535,9 @@ void dpow_statemachinestart(void *ptr) { //printf("abort %s ht.%d due to new checkpoint.%d\n",dp->symbol,checkpoint.blockhash.height,dp->checkpoint.blockhash.height); dp->ratifying -= bp->isratify; - free(ptr); - return; + goto end; + //free(ptr); + //return; } sleep(1); } @@ -609,7 +616,9 @@ void dpow_statemachinestart(void *ptr) printf("[%d] END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",Numallocated,bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest); dp->lastrecvmask = bp->recvmask; dp->ratifying -= bp->isratify; + bp->state = 0xffffffff; +end: // unlock the dest utxo on KMD. if ( (strcmp("KMD",dest->symbol) == 0 ) && (ep->dest.prev_vout != -1) ) { @@ -625,6 +634,6 @@ void dpow_statemachinestart(void *ptr) } // dp->blocks[bp->height] = 0; - bp->state = 0xffffffff; + bp->finished = 0xffffffff; free(ptr); } diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index f23970bb8..949893161 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -143,7 +143,7 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he printf("ht.%d maxblocks.%d\n",ht,dp->maxblocks); for (i=ht-DPOW_MAXFREQ*5; i>ht-DPOW_MAXFREQ*100&&i>DPOW_MAXFREQ; i--) { - if ( (bp= dp->blocks[i]) != 0 && bp->state == 0xffffffff ) //(i % DPOW_MAXFREQ) != 0 && + if ( (bp= dp->blocks[i]) != 0 && bp->finished == 0xffffffff ) //(i % DPOW_MAXFREQ) != 0 && { if ( dp->currentbp == dp->blocks[i] ) dp->currentbp = 0;