From cac7b051ea0a4f7c209e08d28671f3f10933396e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 4 Mar 2018 07:43:51 +0200 Subject: [PATCH] Fix memleaks --- iguana/exchanges/LP_rpc.c | 1 + iguana/exchanges/LP_swap.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 9bde5cd29..2f8e48826 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -468,6 +468,7 @@ cJSON *LP_listreceivedbyaddress(char *symbol,char *coinaddr) } } } + free_json(array); } return(cJSON_Parse("[]")); } else return(electrum_address_gethistory(symbol,coin->electrum,&retjson,coinaddr,zero)); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index e5d6a6a8c..76835a7ba 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -793,13 +793,12 @@ uint32_t LP_swapwait(uint32_t expiration,uint32_t requestid,uint32_t quoteid,int if ( jstr(retjson,"status") != 0 && strcmp(jstr(retjson,"status"),"finished") == 0 ) { finished = (uint32_t)time(NULL); - free(retstr); + free(retstr), retstr = 0; break; } else if ( expiration != 0 && time(NULL) > expiration ) printf("NOT FINISHED.(%s)\n",jprint(retjson,0)); - free_json(retjson); - retjson = 0; + free_json(retjson), retjson = 0; } free(retstr); } @@ -1281,11 +1280,14 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256 privkey,struct basilisk_request *rp,struct LP_quoteinfo *qp,int32_t dynamictrust) { + static void *ctx; struct basilisk_swap *swap; bits256 pubkey25519; uint8_t pubkey33[33]; + if ( ctx == 0 ) + ctx = bitcoin_ctx(); swap = calloc(1,sizeof(*swap)); swap->aliceid = LP_aliceid_calc(qp->desttxid,qp->destvout,qp->feetxid,qp->feevout); swap->I.req.quoteid = rp->quoteid; - swap->ctx = bitcoin_ctx(); + swap->ctx = ctx; vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); swap->I.req = *rp; G.LP_skipstatus[G.LP_numskips] = ((uint64_t)rp->requestid << 32) | rp->quoteid;