Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Otterbein authored and OhGodAGirl committed Dec 3, 2016
1 parent 64c3c9b commit 2dea00e
Showing 1 changed file with 10 additions and 41 deletions.
51 changes: 10 additions & 41 deletions sgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -5939,15 +5939,16 @@ static void *stratum_sthread(void *userdata)
if (!pool->stratum_q)
quit(1, "Failed to create stratum_q in stratum_sthread");

size_t s_size = 4096;
char *s = (char*) malloc(s_size);
while (42) {
char noncehex[12], nonce2hex[20], *s; // s[126 + 16 + 2048];
char noncehex[12], nonce2hex[20];
struct stratum_share *sshare;
uint32_t *hash32, nonce;
size_t s_size = 2500;
unsigned char nonce2[8];
uint64_t *nonce2_64;
struct work *work;
bool submitted;
bool submitted = false;

if (unlikely(pool->removed))
break;
Expand All @@ -5957,17 +5958,10 @@ static void *stratum_sthread(void *userdata)
quit(1, "Stratum q returned empty work");

hash32 = (uint32_t*) work->hash;
if (!(sshare = (struct stratum_share *)calloc(sizeof(struct stratum_share), 1))) {
quit(1, "%s: calloc() failed on sshare.", __func__);
}
if(pool->algorithm.type == ALGO_ETHASH) {
submitted = false;

if (!(sshare = (struct stratum_share *)calloc(sizeof(struct stratum_share), 1))) {
quit(1, "%s: calloc() failed on sshare.", __func__);
}

if (!(s = (char *)calloc(s_size+2, 1))) {
quit(1, "%s: calloc() failed on s.", __func__);
}

sshare->sshare_time = time(NULL);
/* This work item is freed in parse_stratum_response */
sshare->work = work;
Expand All @@ -5990,8 +5984,6 @@ static void *stratum_sthread(void *userdata)
free(ASCIIPoWHash);
}
else if (pool->algorithm.type == ALGO_CRYPTONIGHT) {
sshare = (struct stratum_share *)calloc(sizeof(struct stratum_share), 1);
submitted = false;
char *ASCIIResult;
uint8_t HashResult[32];

Expand All @@ -6009,7 +6001,7 @@ static void *stratum_sthread(void *userdata)
/* Give the stratum share a unique id */
sshare->id = swork_id++;
mutex_unlock(&sshare_lock);
s = malloc(s_size);

snprintf(s, s_size, "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":%d}", pool->XMRAuthID, work->job_id, ASCIINonce, ASCIIResult, sshare->id);

free(ASCIINonce);
Expand All @@ -6019,16 +6011,6 @@ static void *stratum_sthread(void *userdata)
else if(pool->algorithm.type == ALGO_EQUIHASH) {
char *nonce;
char *solution;
submitted = false;

if (!(sshare = (struct stratum_share *)calloc(sizeof(struct stratum_share), 1))) {
quit(1, "%s: calloc() failed on sshare.", __func__);
}

s_size = 77+strlen(pool->rpc_user)+strlen(work->job_id)+strlen(work->ntime)+(64-strlen(work->nonce1))+2694;
if (!(s = (char *)calloc(s_size+2, 1))) {
quit(1, "%s: calloc() failed on s.", __func__);
}

sshare->sshare_time = time(NULL);
/* This work item is freed in parse_stratum_response */
Expand Down Expand Up @@ -6060,16 +6042,6 @@ static void *stratum_sthread(void *userdata)
}

// TODO: check for memory leaks
submitted = false;

if (!(sshare = (struct stratum_share *)calloc(sizeof(struct stratum_share), 1))) {
quit(1, "%s: calloc() failed on sshare.", __func__);
}

if (!(s = (char *)calloc(s_size+2, 1))) {
quit(1, "%s: calloc() failed on s.", __func__);
}

sshare->sshare_time = time(NULL);
/* This work item is freed in parse_stratum_response */
sshare->work = work;
Expand Down Expand Up @@ -6161,16 +6133,13 @@ static void *stratum_sthread(void *userdata)
pool->stale_shares++;
total_stale++;
}

if (s != NULL) {
free(s);
s = NULL;
}
}

/* Freeze the work queue but don't free up its memory in case there is
* work still trying to be submitted to the removed pool. */
tq_freeze(pool->stratum_q);
if (s != NULL)
free(s);

return NULL;
}
Expand Down

0 comments on commit 2dea00e

Please sign in to comment.