Browse Source

Sacrifice curl handle memory on stratum disconnects on all versions of libcurl to avoid curl corruption.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
657e64477b
  1. 19
      util.c

19
util.c

@ -1506,12 +1506,8 @@ static bool setup_stratum_curl(struct pool *pool)
mutex_lock(&pool->stratum_lock); mutex_lock(&pool->stratum_lock);
pool->stratum_active = false; pool->stratum_active = false;
if (pool->stratum_curl) { if (pool->stratum_curl) {
#if CURL_HAS_KEEPALIVE
curl_easy_cleanup(pool->stratum_curl);
#else
/* See above in suspend_stratum */ /* See above in suspend_stratum */
CLOSESOCKET(pool->sock); CLOSESOCKET(pool->sock);
#endif
} }
pool->stratum_curl = curl_easy_init(); pool->stratum_curl = curl_easy_init();
if (unlikely(!pool->stratum_curl)) if (unlikely(!pool->stratum_curl))
@ -1547,7 +1543,9 @@ static bool setup_stratum_curl(struct pool *pool)
} }
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1); curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);
if (curl_easy_perform(curl)) { if (curl_easy_perform(curl)) {
applog(LOG_INFO, "Stratum connect failed to pool %d: %s", pool->pool_no, curl_err_str); applog(LOG_INFO, "Stratum connect failed to pool %d: %s",
pool->pool_no, curl_err_str);
/* Hopefully we can just clean this curl handle up properly */
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
pool->stratum_curl = NULL; pool->stratum_curl = NULL;
return false; return false;
@ -1601,15 +1599,10 @@ void suspend_stratum(struct pool *pool)
mutex_lock(&pool->stratum_lock); mutex_lock(&pool->stratum_lock);
pool->stratum_active = pool->stratum_notify = false; pool->stratum_active = pool->stratum_notify = false;
if (pool->stratum_curl) { if (pool->stratum_curl) {
#if CURL_HAS_KEEPALIVE /* libcurl seems to crash occasionally on this since so just
curl_easy_cleanup(pool->stratum_curl); * sacrifice the ram knowing we leak one curl handle every
#else * time we disconnect stratum. */
/* Old versions of libcurl seem to crash occasionally on this since
* the socket is modified in keep_sockalive in ways curl does not
* know about so sacrifice the ram knowing we leak one curl handle
* every time we disconnect stratum. */
CLOSESOCKET(pool->sock); CLOSESOCKET(pool->sock);
#endif
} }
pool->stratum_curl = NULL; pool->stratum_curl = NULL;
mutex_unlock(&pool->stratum_lock); mutex_unlock(&pool->stratum_lock);

Loading…
Cancel
Save