Fix memory leak with share submission on GPU work structures as discovered by twobitcoins.
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 72 73 74 75 76 77 78 79
diff --git a/cgminer.c b/cgminer.c
index 4f8c66a..cad7719 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3466,7 +3466,7 @@ void switch_pools(struct pool *selected)
}
-static void discard_work(struct work *work)
+void discard_work(struct work *work)
{
if (!work->clone && !work->rolls && !work->mined) {
if (work->pool)
diff --git a/findnonce.c b/findnonce.c
index fcf75f2..e99b7e1 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2012 Con Kolivas
+ * Copyright 2011-2013 Con Kolivas
* Copyright 2011 Nils Schneider
*
* This program is free software; you can redistribute it and/or modify it
@@ -173,7 +173,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;
int found;
@@ -182,10 +182,10 @@ struct pc_data {
static void send_scrypt_nonce(struct pc_data *pcd, uint32_t nonce)
{
struct thr_info *thr = pcd->thr;
- struct work *work = &pcd->work;
+ struct work *work = pcd->work;
if (scrypt_test(work->data, work->target, nonce))
- submit_nonce(thr, &pcd->work, nonce);
+ submit_nonce(thr, work, nonce);
else {
applog(LOG_INFO, "Scrypt error, review settings");
thr->cgpu->hw_errors++;
@@ -217,9 +217,10 @@ static void *postcalc_hash(void *userdata)
if (opt_scrypt)
send_scrypt_nonce(pcd, nonce);
else
- submit_nonce(thr, &pcd->work, nonce);
+ submit_nonce(thr, pcd->work, nonce);
}
+ discard_work(pcd->work);
free(pcd);
return NULL;
@@ -234,7 +235,7 @@ void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res)
}
pcd->thr = thr;
- memcpy(&pcd->work, work, sizeof(struct work));
+ pcd->work = copy_work(work);
memcpy(&pcd->res, res, BUFFERSIZE);
if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {
diff --git a/miner.h b/miner.h
index a44b9c1..bd24305 100644
--- a/miner.h
+++ b/miner.h
@@ -1119,6 +1119,7 @@ extern int curses_int(const char *query);
extern char *curses_input(const char *query);
extern void kill_work(void);
extern void switch_pools(struct pool *selected);
+extern void discard_work(struct work *work);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
extern void zero_bestshare(void);