From 19fcb5eae7e3993165ed7450368f0032755539ca Mon Sep 17 00:00:00 2001 From: Jan Berdajs Date: Fri, 11 Jul 2014 19:02:44 +0200 Subject: [PATCH] improve locking to prevent race condition stratum could respond faster than we are able to add the sent share into the hash, which could cause memory leaks --- sgminer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sgminer.c b/sgminer.c index c277e0f6..2d4577dd 100644 --- a/sgminer.c +++ b/sgminer.c @@ -5450,9 +5450,13 @@ static void *stratum_sthread(void *userdata) while (time(NULL) < sshare->sshare_time + 120) { bool sessionid_match; + mutex_lock(&sshare_lock); if (likely(stratum_send(pool, s, strlen(s)))) { int ssdiff; + if (pool_tclear(pool, &pool->submit_fail)) + applog(LOG_WARNING, "%s communication resumed, submitting work", get_pool_name(pool)); + sshare->sshare_sent = time(NULL); ssdiff = sshare->sshare_sent - sshare->sshare_time; if (opt_debug || ssdiff > 0) { @@ -5460,18 +5464,17 @@ static void *stratum_sthread(void *userdata) pool->pool_no, ssdiff); } - mutex_lock(&sshare_lock); HASH_ADD_INT(stratum_shares, id, sshare); pool->sshares++; mutex_unlock(&sshare_lock); - if (pool_tclear(pool, &pool->submit_fail)) - applog(LOG_WARNING, "%s communication resumed, submitting work", get_pool_name(pool)); - applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db"); submitted = true; break; } + else { + mutex_unlock(&sshare_lock); + } if (!pool_tset(pool, &pool->submit_fail) && cnx_needed(pool)) { applog(LOG_WARNING, "%s stratum share submission failure", get_pool_name(pool)); total_ro++;