Browse Source

Fix various memory leaks

master
Con Kolivas 11 years ago
parent
commit
c4f0d57ae8
  1. 1
      src/bitcoin.c
  2. 1
      src/connector.c
  3. 7
      src/generator.c
  4. 2
      src/libckpool.h
  5. 22
      src/stratifier.c

1
src/bitcoin.c

@ -381,6 +381,7 @@ bool submit_block(connsock_t *cs, char *params)
rpc_req = ckalloc(len); rpc_req = ckalloc(len);
sprintf(rpc_req, "{\"method\": \"submitblock\", \"params\": [\"%s\"]}\n", params); sprintf(rpc_req, "{\"method\": \"submitblock\", \"params\": [\"%s\"]}\n", params);
val = json_rpc_call(cs, rpc_req); val = json_rpc_call(cs, rpc_req);
dealloc(rpc_req);
if (!val) { if (!val) {
LOGWARNING("Failed to get valid json response to submitblock"); LOGWARNING("Failed to get valid json response to submitblock");
return ret; return ret;

1
src/connector.c

@ -499,6 +499,7 @@ retry:
goto retry; goto retry;
out: out:
dealloc(buf);
return ret; return ret;
} }

7
src/generator.c

@ -837,7 +837,7 @@ static void send_notify(proxy_instance_t *proxi, int sockd)
mutex_lock(&proxi->notify_lock); mutex_lock(&proxi->notify_lock);
ni = proxi->current_notify; ni = proxi->current_notify;
for (i = 0; i < ni->merkles; i++) 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 */ /* Use our own jobid instead of the server's one for easy lookup */
json_msg = json_pack("{sisssssssosssssssb}", json_msg = json_pack("{sisssssssosssssssb}",
"jobid", ni->id, "prevhash", ni->prevhash, "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); ret = gen_loop(pi);
for (i = 0; i < ckp->btcds; si = ckp->servers[i], i++) { 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->data);
dealloc(si); dealloc(si);
} }

2
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) 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) static inline void json_set_int(json_t *val, const char *key, int integer)

22
src/stratifier.c

@ -464,7 +464,7 @@ static void update_base(ckpool_t *ckp)
for (i = 0; i < wb->merkles; i++) { for (i = 0; i < wb->merkles; i++) {
strcpy(&wb->merklehash[i][0], json_string_value(json_array_get(arr, i))); strcpy(&wb->merklehash[i][0], json_string_value(json_array_get(arr, i)));
hex2bin(&wb->merklebin[i][0], &wb->merklehash[i][0], 32); 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); json_decref(val);
@ -782,8 +782,11 @@ static void drop_client(int id)
if (!old_client) { if (!old_client) {
stats.reusable_clients++; stats.reusable_clients++;
HASH_ADD(hh, disconnected_instances, enonce1_64, sizeof(uint64_t), client); HASH_ADD(hh, disconnected_instances, enonce1_64, sizeof(uint64_t), client);
} else } else {
dealloc(client->workername);
dealloc(client->useragent);
free(client); free(client);
}
ck_dwilock(&instance_lock); ck_dwilock(&instance_lock);
} }
ck_uilock(&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); ck_rlock(&workbase_lock);
HASH_FIND_INT(workbases, &id, wb); HASH_FIND_INT(workbases, &id, wb);
if (unlikely(!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); strcpy(idstring, job_id);
logdir = current_workbase->logdir; logdir = current_workbase->logdir;
goto out_unlock; goto out_unlock;
@ -1489,7 +1492,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg,
__bin2hex(hexhash, sharehash, 32); __bin2hex(hexhash, sharehash, 32);
if (id < blockchange_id) { 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; goto out_unlock;
} }
if ((int)strlen(nonce2) != wb->enonce2varlen * 2) { 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 */ /* Ntime cannot be less, but allow forward ntime rolling up to max */
if (ntime32 < wb->ntime32 || ntime32 > wb->ntime32 + 7000) { 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; goto out_unlock;
} }
invalid = false; invalid = false;
@ -1525,14 +1528,14 @@ out_unlock:
client->id, sdiff, diff, wdiffsuffix, hexhash); client->id, sdiff, diff, wdiffsuffix, hexhash);
result = true; result = true;
} else { } 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", LOGINFO("Rejected client %d dupe diff %.1f/%.0f/%s: %s",
client->id, sdiff, diff, wdiffsuffix, hexhash); client->id, sdiff, diff, wdiffsuffix, hexhash);
} }
} else { } else {
LOGINFO("Rejected client %d high diff %.1f/%.0f/%s: %s", LOGINFO("Rejected client %d high diff %.1f/%.0f/%s: %s",
client->id, sdiff, diff, wdiffsuffix, hexhash); 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 } else
LOGINFO("Rejected client %d invalid share", client->id); 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) if (!err_val)
err_val = json_null(); err_val = json_null();
out: out:
json_object_set_nocheck(json_msg, "error", err_val); json_object_set_new_nocheck(json_msg, "error", err_val);
json_object_set_nocheck(json_msg, "result", result_val); json_object_set_new_nocheck(json_msg, "result", result_val);
stratum_add_send(json_msg, client_id); stratum_add_send(json_msg, client_id);
if (update) { if (update) {
@ -2061,6 +2064,7 @@ int stratifier(proc_instance_t *pi)
do { do {
buf = send_recv_proc(ckp->generator, "ping"); buf = send_recv_proc(ckp->generator, "ping");
} while (!buf); } while (!buf);
dealloc(buf);
cklock_init(&instance_lock); cklock_init(&instance_lock);

Loading…
Cancel
Save