Commit d5d4d1da164ffd8b24809e0fdc4dbd3b9db4a9f0

Con Kolivas 2011-06-30T14:41:01

Don't want to free the work data out of the transient structs.

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)) {