Skip to content

Commit

Permalink
stratum: properly free jobs on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed May 23, 2015
1 parent ee9c821 commit 69852a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2310,10 +2310,9 @@ static void *stratum_thread(void *userdata)
if (switchn != pool_switch_count) goto pool_switched;

if (!stratum_socket_full(&stratum, opt_timeout)) {
if (!opt_quiet)
if (opt_debug)
applog(LOG_WARNING, "Stratum connection timed out");
s = NULL;
continue;
} else
s = stratum_recv_line(&stratum);

Expand All @@ -2322,7 +2321,7 @@ static void *stratum_thread(void *userdata)

if (!s) {
stratum_disconnect(&stratum);
applog(LOG_ERR, "Stratum connection interrupted");
applog(LOG_WARNING, "Stratum connection interrupted");
continue;
}
if (!stratum_handle_method(&stratum, s))
Expand Down Expand Up @@ -2418,8 +2417,12 @@ bool pool_switch(int pooln)
struct pool_infos* p = NULL;

// save prev stratum connection infos (struct)
if (prev->type & POOL_STRATUM)
if (prev->type & POOL_STRATUM) {
// may not be the right moment to free,
// to check if required on submit...
stratum_free_job(&stratum);
prev->stratum = stratum;
}

if (pooln < num_pools) {
cur_pooln = pooln;
Expand Down
1 change: 1 addition & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ void stratum_disconnect(struct stratum_ctx *sctx);
bool stratum_subscribe(struct stratum_ctx *sctx);
bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *pass);
bool stratum_handle_method(struct stratum_ctx *sctx, const char *s);
void stratum_free_job(struct stratum_ctx *sctx);

void hashlog_remember_submit(struct work* work, uint32_t nonce);
void hashlog_remember_scan_range(struct work* work);
Expand Down
22 changes: 22 additions & 0 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,25 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url)
return true;
}

void stratum_free_job(struct stratum_ctx *sctx)
{
pthread_mutex_lock(&stratum_work_lock);
if (sctx->job.job_id) {
free(sctx->job.job_id);
}
if (sctx->job.merkle_count) {
for (int i = 0; i < sctx->job.merkle_count; i++) {
free(sctx->job.merkle[i]);
sctx->job.merkle[i] = NULL;
}
free(sctx->job.merkle);
}
free(sctx->job.coinbase);
// note: xnonce2 is not allocated
memset(&(sctx->job.job_id), 0, sizeof(struct stratum_job));
pthread_mutex_unlock(&stratum_work_lock);
}

void stratum_disconnect(struct stratum_ctx *sctx)
{
pthread_mutex_lock(&stratum_sock_lock);
Expand All @@ -1005,6 +1024,9 @@ void stratum_disconnect(struct stratum_ctx *sctx)
// free(sctx->sockbuf);
// sctx->sockbuf = NULL;
}
if (sctx->job.job_id) {
stratum_free_job(sctx);
}
pthread_mutex_unlock(&stratum_sock_lock);
}

Expand Down

0 comments on commit 69852a2

Please sign in to comment.