Don't want to free the work data out of the transient structs.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/cpu-miner.c b/cpu-miner.c
index f67b384..4dd361b 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -645,7 +645,7 @@ out:
struct submit_data {
struct thr_info *thr;
- struct work work_in;
+ struct work *work_in;
pthread_t pth;
};
@@ -688,10 +688,15 @@ static bool submit_work_async(struct thr_info *thr, const struct work *work_in)
applog(LOG_ERR, "Failed to malloc sd in submit_work_async");
return false;
}
+ sd->work_in = malloc(sizeof(struct work));
+ if (unlikely(!sd->work_in)) {
+ applog(LOG_ERR, "Failed to malloc work_in in submit_work_async");
+ return false;
+ }
- memcpy(&sd->work_in, work_in, sizeof(struct work));
+ memcpy(sd->work_in, work_in, sizeof(struct work));
/* Pass the thread id to the work struct for per-thread accounting */
- sd->work_in.thr_id = thr->id;
+ sd->work_in->thr_id = thr->id;
if (pthread_create(&sd->pth, NULL, submit_work, (void *)sd)) {
applog(LOG_ERR, "Failed to create submit_thread");
diff --git a/findnonce.c b/findnonce.c
index 877e3f5..2502091 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -137,7 +137,7 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) {
struct pc_data {
struct thr_info *thr;
- struct work work;
+ struct work *work;
uint32_t res[MAXBUFFERS];
pthread_t pth;
};
@@ -146,8 +146,8 @@ static void *postcalc_hash(void *userdata)
{
struct pc_data *pcd = (struct pc_data *)userdata;
struct thr_info *thr = pcd->thr;
- dev_blk_ctx *blk = &pcd->work.blk;
- struct work *work = &pcd->work;
+ dev_blk_ctx *blk = &pcd->work->blk;
+ struct work *work = pcd->work;
uint32_t start;
cl_uint A, B, C, D, E, F, G, H;
@@ -236,9 +236,14 @@ void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res)
applog(LOG_ERR, "Failed to malloc pc_data in postcalc_hash_async");
return;
}
+ pcd->work = calloc(1, sizeof(struct work));
+ if (unlikely(!pcd->work)) {
+ applog(LOG_ERR, "Failed to malloc work in postcalc_hash_async");
+ return;
+ }
pcd->thr = thr;
- memcpy(&pcd->work, work, sizeof(struct work));
+ memcpy(pcd->work, work, sizeof(struct work));
memcpy(&pcd->res, res, BUFFERSIZE);
if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {