diff --git a/src/bitcoin.c b/src/bitcoin.c index b7c7bd4a..eb6d8c78 100644 --- a/src/bitcoin.c +++ b/src/bitcoin.c @@ -381,6 +381,7 @@ bool submit_block(connsock_t *cs, char *params) rpc_req = ckalloc(len); sprintf(rpc_req, "{\"method\": \"submitblock\", \"params\": [\"%s\"]}\n", params); val = json_rpc_call(cs, rpc_req); + dealloc(rpc_req); if (!val) { LOGWARNING("Failed to get valid json response to submitblock"); return ret; diff --git a/src/connector.c b/src/connector.c index afcfa671..a1fb13c2 100644 --- a/src/connector.c +++ b/src/connector.c @@ -499,6 +499,7 @@ retry: goto retry; out: + dealloc(buf); return ret; } diff --git a/src/generator.c b/src/generator.c index 73f9cab7..0dc724d1 100644 --- a/src/generator.c +++ b/src/generator.c @@ -837,7 +837,7 @@ static void send_notify(proxy_instance_t *proxi, int sockd) mutex_lock(&proxi->notify_lock); ni = proxi->current_notify; for (i = 0; i < ni->merkles; i++) - json_array_append(merkle_arr, json_string(&ni->merklehash[i][0])); + json_array_append_new(merkle_arr, json_string(&ni->merklehash[i][0])); /* Use our own jobid instead of the server's one for easy lookup */ json_msg = json_pack("{sisssssssosssssssb}", "jobid", ni->id, "prevhash", ni->prevhash, @@ -1249,6 +1249,11 @@ static int server_mode(ckpool_t *ckp, proc_instance_t *pi) ret = gen_loop(pi); for (i = 0; i < ckp->btcds; si = ckp->servers[i], i++) { + connsock_t *cs = &si->cs; + + dealloc(cs->url); + dealloc(cs->port); + dealloc(cs->auth); dealloc(si->data); dealloc(si); } diff --git a/src/libckpool.h b/src/libckpool.h index 4a0340d1..c3fe75ab 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -234,7 +234,7 @@ static inline void json_strdup(char **buf, json_t *val, const char *key) static inline void json_set_string(json_t *val, const char *key, const char *str) { - json_object_set_nocheck(val, key, json_string(str)); + json_object_set_new_nocheck(val, key, json_string(str)); } static inline void json_set_int(json_t *val, const char *key, int integer) diff --git a/src/stratifier.c b/src/stratifier.c index 29fc3926..1c6a127d 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -464,7 +464,7 @@ static void update_base(ckpool_t *ckp) for (i = 0; i < wb->merkles; i++) { strcpy(&wb->merklehash[i][0], json_string_value(json_array_get(arr, i))); hex2bin(&wb->merklebin[i][0], &wb->merklehash[i][0], 32); - json_array_append(wb->merkle_array, json_string(&wb->merklehash[i][0])); + json_array_append_new(wb->merkle_array, json_string(&wb->merklehash[i][0])); } } json_decref(val); @@ -782,8 +782,11 @@ static void drop_client(int id) if (!old_client) { stats.reusable_clients++; HASH_ADD(hh, disconnected_instances, enonce1_64, sizeof(uint64_t), client); - } else + } else { + dealloc(client->workername); + dealloc(client->useragent); free(client); + } ck_dwilock(&instance_lock); } ck_uilock(&instance_lock); @@ -1476,7 +1479,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, ck_rlock(&workbase_lock); HASH_FIND_INT(workbases, &id, wb); if (unlikely(!wb)) { - json_object_set_nocheck(json_msg, "reject-reason", json_string("Invalid JobID")); + json_set_string(json_msg, "reject-reason", "Invalid JobID"); strcpy(idstring, job_id); logdir = current_workbase->logdir; goto out_unlock; @@ -1489,7 +1492,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, __bin2hex(hexhash, sharehash, 32); if (id < blockchange_id) { - json_object_set_nocheck(json_msg, "reject-reason", json_string("Stale")); + json_set_string(json_msg, "reject-reason", "Stale"); goto out_unlock; } if ((int)strlen(nonce2) != wb->enonce2varlen * 2) { @@ -1498,7 +1501,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, } /* Ntime cannot be less, but allow forward ntime rolling up to max */ if (ntime32 < wb->ntime32 || ntime32 > wb->ntime32 + 7000) { - json_object_set_nocheck(json_msg, "reject-reason", json_string("Ntime out of range")); + json_set_string(json_msg, "reject-reason", "Ntime out of range"); goto out_unlock; } invalid = false; @@ -1525,14 +1528,14 @@ out_unlock: client->id, sdiff, diff, wdiffsuffix, hexhash); result = true; } else { - json_object_set_nocheck(json_msg, "reject-reason", json_string("Duplicate")); + json_set_string(json_msg, "reject-reason", "Duplicate"); LOGINFO("Rejected client %d dupe diff %.1f/%.0f/%s: %s", client->id, sdiff, diff, wdiffsuffix, hexhash); } } else { LOGINFO("Rejected client %d high diff %.1f/%.0f/%s: %s", client->id, sdiff, diff, wdiffsuffix, hexhash); - json_object_set_nocheck(json_msg, "reject-reason", json_string("Above target")); + json_set_string(json_msg, "reject-reason", "Above target"); } } else LOGINFO("Rejected client %d invalid share", client->id); @@ -1733,8 +1736,8 @@ static void parse_instance_msg(int client_id, json_t *msg) if (!err_val) err_val = json_null(); out: - json_object_set_nocheck(json_msg, "error", err_val); - json_object_set_nocheck(json_msg, "result", result_val); + json_object_set_new_nocheck(json_msg, "error", err_val); + json_object_set_new_nocheck(json_msg, "result", result_val); stratum_add_send(json_msg, client_id); if (update) { @@ -2061,6 +2064,7 @@ int stratifier(proc_instance_t *pi) do { buf = send_recv_proc(ckp->generator, "ping"); } while (!buf); + dealloc(buf); cklock_init(&instance_lock);