diff --git a/src/generator.c b/src/generator.c index 7a96e095..5acc3227 100644 --- a/src/generator.c +++ b/src/generator.c @@ -153,7 +153,8 @@ retry: keep_sockalive(cs->fd); /* Test we can connect, authorise and get a block template */ - gbt = si->data; + gbt = ckzalloc(sizeof(gbtbase_t)); + si->data = gbt; if (!gen_gbtbase(cs, gbt)) { LOGINFO("Failed to get test block template from %s:%s!", cs->url, cs->port); @@ -192,7 +193,6 @@ static void kill_server(server_instance_t *si) dealloc(cs->port); dealloc(cs->auth); dealloc(si->data); - dealloc(si); } static int gen_loop(proc_instance_t *pi) @@ -1299,15 +1299,11 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi) ckp->servers = ckalloc(sizeof(server_instance_t *) * ckp->btcds); for (i = 0; i < ckp->btcds; i++) { - gbtbase_t *gbt; - ckp->servers[i] = ckzalloc(sizeof(server_instance_t)); si = ckp->servers[i]; si->url = ckp->btcdurl[i]; si->auth = ckp->btcdauth[i]; si->pass = ckp->btcdpass[i]; - gbt = ckzalloc(sizeof(gbtbase_t)); - si->data = gbt; } ret = gen_loop(pi); @@ -1315,6 +1311,7 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi) for (i = 0; i < ckp->btcds; i++) { si = ckp->servers[i]; kill_server(si); + dealloc(si); } dealloc(ckp->servers); return ret; diff --git a/src/stratifier.c b/src/stratifier.c index 19074635..37ede260 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -331,7 +331,7 @@ static void generate_coinbase(ckpool_t *ckp, workbase_t *wb) len += wb->enonce1varlen; len += wb->enonce2varlen; - wb->coinb2bin = ckalloc(128); + wb->coinb2bin = ckzalloc(128); memcpy(wb->coinb2bin, "\x0a\x63\x6b\x70\x6f\x6f\x6c", 7); wb->coinb2len = 7; if (ckp->btcsig) { @@ -1841,7 +1841,7 @@ static json_t *__stratum_notify(bool clean) current_workbase->prevhash, current_workbase->coinb1, current_workbase->coinb2, - json_copy(current_workbase->merkle_array), + json_deep_copy(current_workbase->merkle_array), current_workbase->bbversion, current_workbase->nbit, current_workbase->ntime,