Commit 0465fef5535e55c5284404e59192659b16bcadb0

Con Kolivas 2012-11-05T23:22:36

Discard record of stratum shares sent and report lost shares on disconnection since they will never be reported back.

diff --git a/cgminer.c b/cgminer.c
index 0ac54da..9139412 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4305,6 +4305,25 @@ out:
 
 static void pool_resus(struct pool *pool);
 
+static void clear_stratum_shares(struct pool *pool)
+{
+	struct stratum_share *sshare, *tmpshare;
+	int cleared = 0;
+
+	mutex_lock(&sshare_lock);
+	HASH_ITER(hh, stratum_shares, sshare, tmpshare) {
+		if (sshare->work.pool == pool) {
+			HASH_DEL(stratum_shares, sshare);
+			free(sshare);
+			cleared++;
+		}
+	}
+	mutex_unlock(&sshare_lock);
+
+	if (cleared)
+		applog(LOG_WARNING, "Lost %d shares due to stratum disconnect on pool %d", cleared, pool->pool_no);
+}
+
 /* One stratum thread per pool that has stratum waits on the socket checking
  * for new messages and for the integrity of the socket connection. We reset
  * the connection based on the integrity of the receive side only as the send
@@ -4341,6 +4360,11 @@ static void *stratum_thread(void *userdata)
 			pool->getfail_occasions++;
 			total_go++;
 
+			/* If the socket to our stratum pool disconnects, all
+			 * tracked submitted shares are lost and we will leak
+			 * the memory if we don't discard their records. */
+			clear_stratum_shares(pool);
+
 			if (initiate_stratum(pool) && auth_stratum(pool))
 				continue;