Browse Source

Fix memory leak with share submission on GPU work structures as discovered by twobitcoins.

Con Kolivas 13 years ago
parent
commit
5412323e26
3 changed files with 9 additions and 7 deletions
  1. 1 1
      cgminer.c
  2. 7 6
      findnonce.c
  3. 1 0
      miner.h

+ 1 - 1
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)

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

+ 1 - 0
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);