Merge pull request #521 from mborodin/upstream Some meory leaks fixed
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
diff --git a/api.c b/api.c
index 302196d..587504c 100644
--- a/api.c
+++ b/api.c
@@ -719,6 +719,7 @@ static void io_free()
do {
io_next = io_list->next;
+ free(io_list->io_data->ptr);
free(io_list->io_data);
free(io_list);
@@ -4399,6 +4400,7 @@ void api(int api_thr_id)
if (!opt_api_listen) {
applog(LOG_DEBUG, "API not running%s", UNAVAILABLE);
+ free(apisock);
return;
}
@@ -4416,6 +4418,7 @@ void api(int api_thr_id)
if (ips == 0) {
applog(LOG_WARNING, "API not running (no valid IPs specified)%s", UNAVAILABLE);
+ free(apisock);
return;
}
}
@@ -4427,6 +4430,7 @@ void api(int api_thr_id)
*apisock = socket(AF_INET, SOCK_STREAM, 0);
if (*apisock == INVSOCK) {
applog(LOG_ERR, "API1 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
+ free(apisock);
return;
}
@@ -4438,6 +4442,7 @@ void api(int api_thr_id)
serv.sin_addr.s_addr = inet_addr(localaddr);
if (serv.sin_addr.s_addr == (in_addr_t)INVINETADDR) {
applog(LOG_ERR, "API2 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
+ free(apisock);
return;
}
}
@@ -4476,12 +4481,14 @@ void api(int api_thr_id)
if (bound == 0) {
applog(LOG_ERR, "API bind to port %d failed (%s)%s", port, binderror, UNAVAILABLE);
+ free(apisock);
return;
}
if (SOCKETFAIL(listen(*apisock, QUEUE))) {
applog(LOG_ERR, "API3 initialisation failed (%s)%s", SOCKERRMSG, UNAVAILABLE);
CLOSESOCKET(*apisock);
+ free(apisock);
return;
}
@@ -4618,6 +4625,8 @@ die:
;
pthread_cleanup_pop(true);
+ free(apisock);
+
if (opt_debug)
applog(LOG_DEBUG, "API: terminating due to: %s",
do_a_quit ? "QUIT" : (do_a_restart ? "RESTART" : (bye ? "BYE" : "UNKNOWN!")));
diff --git a/util.c b/util.c
index f5472c3..4e3d502 100644
--- a/util.c
+++ b/util.c
@@ -1738,8 +1738,10 @@ bool parse_method(struct pool *pool, char *s)
}
method = json_object_get(val, "method");
- if (!method)
+ if (!method) {
+ json_decref(val);
return ret;
+ }
err_val = json_object_get(val, "error");
params = json_object_get(val, "params");
@@ -1753,42 +1755,51 @@ bool parse_method(struct pool *pool, char *s)
applog(LOG_INFO, "JSON-RPC method decode failed: %s", ss);
+ json_decref(val);
free(ss);
return ret;
}
buf = (char *)json_string_value(method);
- if (!buf)
+ if (!buf) {
+ json_decref(val);
return ret;
+ }
if (!strncasecmp(buf, "mining.notify", 13)) {
if (parse_notify(pool, params))
pool->stratum_notify = ret = true;
else
pool->stratum_notify = ret = false;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "mining.set_difficulty", 21) && parse_diff(pool, params)) {
ret = true;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "client.reconnect", 16) && parse_reconnect(pool, params)) {
ret = true;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "client.get_version", 18) && send_version(pool, val)) {
ret = true;
+ json_decref(val);
return ret;
}
if (!strncasecmp(buf, "client.show_message", 19) && show_message(pool, params)) {
ret = true;
+ json_decref(val);
return ret;
}
+ json_decref(val);
return ret;
}
@@ -1831,13 +1842,16 @@ bool auth_stratum(struct pool *pool)
applog(LOG_WARNING, "pool %d JSON stratum auth failed: %s", pool->pool_no, ss);
free(ss);
- return ret;
+ goto out;
}
ret = true;
applog(LOG_INFO, "Stratum authorisation success for pool %d", pool->pool_no);
pool->probed = true;
successful_connect = true;
+
+out:
+ json_decref(val);
return ret;
}
@@ -2383,6 +2397,7 @@ out:
applog(LOG_DEBUG, "Failed to resume stratum, trying afresh");
noresume = true;
+ json_decref(val);
goto resend;
}
applog(LOG_DEBUG, "Initiate stratum failed");
@@ -2390,6 +2405,7 @@ out:
suspend_stratum(pool);
}
+ json_decref(val);
return ret;
}