Don't keep any json references around with stratum structures.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/util.c b/util.c
index 09c351b..db100ec 100644
--- a/util.c
+++ b/util.c
@@ -992,10 +992,9 @@ static bool parse_stratum(struct pool *pool, char *s)
}
out:
- if (!ret) {
- if (val)
- json_decref(val);
- }
+ if (val)
+ json_decref(val);
+
return ret;
}
@@ -1020,11 +1019,8 @@ bool auth_stratum(struct pool *pool)
goto out;
out:
- if (!ret) {
- if (val)
- json_decref(val);
- } else
- pool->stratum_val = val;
+ if (val)
+ json_decref(val);
return ret;
}
@@ -1098,13 +1094,13 @@ bool initiate_stratum(struct pool *pool)
applog(LOG_WARNING, "Failed to get mining notify in initiate_stratum");
goto out;
}
- pool->subscription = (char *)json_string_value(json_array_get(notify_val, 1));
+ pool->subscription = strdup(json_string_value(json_array_get(notify_val, 1)));
if (!pool->subscription) {
applog(LOG_WARNING, "Failed to get a subscription in initiate_stratum");
goto out;
}
- pool->nonce1 = (char *)json_string_value(json_array_get(res_val, 1));
+ pool->nonce1 = strdup(json_string_value(json_array_get(res_val, 1)));
if (!pool->nonce1) {
applog(LOG_WARNING, "Failed to get nonce1 in initiate_stratum");
goto out;
@@ -1117,18 +1113,18 @@ bool initiate_stratum(struct pool *pool)
ret = true;
out:
- if (!ret) {
- CLOSESOCKET(pool->sock);
- if (val)
- json_decref(val);
- } else {
+ if (val)
+ json_decref(val);
+
+ if (ret) {
pool->stratum_active = true;
pool->stratum_val = val;
if (opt_protocol) {
applog(LOG_DEBUG, "Pool %d confirmed mining.notify with subscription %s extranonce1 %s extranonce2 %d",
pool->pool_no, pool->subscription, pool->nonce1, pool->nonce2);
}
- }
+ } else
+ CLOSESOCKET(pool->sock);
return ret;
}