Browse Source

Bugfix: Check that the stratum_share struct for a failed submission is still in the submission hashtable before trying to delete it

If the stratum share resubmission code pulls it out first, it could be gone and freed already
Luke Dashjr 12 years ago
parent
commit
707c9f6f3c
1 changed files with 15 additions and 3 deletions
  1. 15 3
      miner.c

+ 15 - 3
miner.c

@@ -4139,6 +4139,7 @@ next_write_sws:
 			
 			
 			char *s = sws->s;
 			char *s = sws->s;
 			struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1);
 			struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1);
+			int sshare_id;
 			uint32_t nonce;
 			uint32_t nonce;
 			char *noncehex;
 			char *noncehex;
 			
 			
@@ -4149,6 +4150,7 @@ next_write_sws:
 			
 			
 			mutex_lock(&sshare_lock);
 			mutex_lock(&sshare_lock);
 			/* Give the stratum share a unique id */
 			/* Give the stratum share a unique id */
+			sshare_id =
 			sshare->id = swork_id++;
 			sshare->id = swork_id++;
 			HASH_ADD_INT(stratum_shares, id, sshare);
 			HASH_ADD_INT(stratum_shares, id, sshare);
 			sprintf(s, "{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\": %d, \"method\": \"mining.submit\"}",
 			sprintf(s, "{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\": %d, \"method\": \"mining.submit\"}",
@@ -4167,14 +4169,24 @@ next_write_sws:
 			} else if (!pool_tset(pool, &pool->submit_fail)) {
 			} else if (!pool_tset(pool, &pool->submit_fail)) {
 				// Undo stuff
 				// Undo stuff
 				mutex_lock(&sshare_lock);
 				mutex_lock(&sshare_lock);
-				HASH_DEL(stratum_shares, sshare);
+				// NOTE: Need to find it again in case something else has consumed it already (like the stratum-disconnect resubmitter...)
+				HASH_FIND_INT(stratum_shares, &sshare_id, sshare);
+				if (sshare)
+					HASH_DEL(stratum_shares, sshare);
 				mutex_unlock(&sshare_lock);
 				mutex_unlock(&sshare_lock);
-				free_work(sshare->work);
-				free(sshare);
+				if (sshare)
+				{
+					free_work(sshare->work);
+					free(sshare);
+				}
 				
 				
 				applog(LOG_WARNING, "Pool %d stratum share submission failure", pool->pool_no);
 				applog(LOG_WARNING, "Pool %d stratum share submission failure", pool->pool_no);
 				total_ro++;
 				total_ro++;
 				pool->remotefail_occasions++;
 				pool->remotefail_occasions++;
+				
+				if (!sshare)
+					goto next_write_sws_del;
+				
 				goto next_write_sws;
 				goto next_write_sws;
 			}
 			}
 		}
 		}