Use stack memory in test_work_current, avoiding a malloc/free cycle each time.
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
diff --git a/cgminer.c b/cgminer.c
index 6ed3523..c1cd938 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4006,15 +4006,15 @@ static void set_blockdiff(const struct work *work)
static bool test_work_current(struct work *work)
{
bool ret = true;
- char *hexstr;
+ char hexstr[20];
if (work->mandatory)
return ret;
/* Hack to work around dud work sneaking into test */
- hexstr = bin2hex(work->data + 8, 18);
+ __bin2hex(hexstr, work->data + 8, 18);
if (!strncmp(hexstr, "000000000000000000000000000000000000", 36))
- goto out_free;
+ return ret;
/* Search to see if this block exists yet and if not, consider it a
* new block and set the current block details to this one */
@@ -4049,7 +4049,7 @@ static bool test_work_current(struct work *work)
applog(LOG_DEBUG, "Deleted block %d from database", deleted_block);
set_curblock(hexstr, work->data);
if (unlikely(new_blocks == 1))
- goto out_free;
+ return ret;
work->work_block = ++work_block;
@@ -4072,8 +4072,6 @@ static bool test_work_current(struct work *work)
}
}
work->longpoll = false;
-out_free:
- free(hexstr);
return ret;
}