Discard record of stratum shares sent and report lost shares on disconnection since they will never be reported back.
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
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;