diff --git a/src/generator.c b/src/generator.c index 998cd7b1..c689e934 100644 --- a/src/generator.c +++ b/src/generator.c @@ -611,7 +611,7 @@ static bool parse_diff(proxy_instance_t *proxi, json_t *val) static bool send_version(proxy_instance_t *proxi, json_t *val) { - json_t *json_msg, *id_val = json_object_get(val, "id"); + json_t *json_msg, *id_val = json_object_dup(val, "id"); connsock_t *cs = proxi->cs; bool ret; @@ -1070,10 +1070,10 @@ static void *proxy_send(void *arg) if (jobid) { val = json_pack("{s[ssooo]soss}", "params", proxi->auth, jobid, - json_object_get(msg->json_msg, "nonce2"), - json_object_get(msg->json_msg, "ntime"), - json_object_get(msg->json_msg, "nonce"), - "id", json_object_get(msg->json_msg, "id"), + json_object_dup(msg->json_msg, "nonce2"), + json_object_dup(msg->json_msg, "ntime"), + json_object_dup(msg->json_msg, "nonce"), + "id", json_object_dup(msg->json_msg, "id"), "method", "mining.submit"); free(jobid); ret = send_json_msg(cs, val); diff --git a/src/libckpool.c b/src/libckpool.c index c7fc64ef..7e070dde 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -795,6 +795,11 @@ char *json_array_string(json_t *val, unsigned int entry) return NULL; } +json_t *json_object_dup(json_t *val, const char *entry) +{ + return json_copy(json_object_get(val, entry)); +} + /* Align a size_t to 4 byte boundaries for fussy arches */ void align_len(size_t *len) diff --git a/src/libckpool.h b/src/libckpool.h index a3c14564..30c5eb26 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -357,6 +357,7 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu const char *__json_array_string(json_t *val, unsigned int entry); char *json_array_string(json_t *val, unsigned int entry); +json_t *json_object_dup(json_t *val, const char *entry); void align_len(size_t *len); void realloc_strcat(char **ptr, const char *s); diff --git a/src/stratifier.c b/src/stratifier.c index abacf7f1..845f3e5e 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -567,7 +567,7 @@ static void update_notify(ckpool_t *ckp) wb->coinb2len = strlen(wb->coinb2) / 2; wb->coinb2bin = ckalloc(wb->coinb2len); hex2bin(wb->coinb2bin, wb->coinb2, wb->coinb2len); - wb->merkle_array = json_copy(json_object_get(val, "merklehash")); + wb->merkle_array = json_object_dup(val, "merklehash"); wb->merkles = json_array_size(wb->merkle_array); for (i = 0; i < wb->merkles; i++) { strcpy(&wb->merklehash[i][0], json_string_value(json_array_get(wb->merkle_array, i))); @@ -1580,7 +1580,7 @@ out_unlock: json_set_double(val, "sdiff", sdiff); json_set_string(val, "hash", hexhash); json_set_bool(val, "result", result); - json_object_set(val, "reject-reason", json_object_get(json_msg, "reject-reason")); + json_object_set(val, "reject-reason", json_object_dup(json_msg, "reject-reason")); json_object_set(val, "error", *err_val); s = json_dumps(val, 0); len = strlen(s);