Browse Source

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

nfactor-troky
Con Kolivas 12 years ago
parent
commit
5412323e26
  1. 2
      cgminer.c
  2. 13
      findnonce.c
  3. 1
      miner.h

2
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->clone && !work->rolls && !work->mined) {
if (work->pool) if (work->pool)

13
findnonce.c

@ -1,5 +1,5 @@
/* /*
* Copyright 2011-2012 Con Kolivas * Copyright 2011-2013 Con Kolivas
* Copyright 2011 Nils Schneider * Copyright 2011 Nils Schneider
* *
* This program is free software; you can redistribute it and/or modify it * 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 pc_data {
struct thr_info *thr; struct thr_info *thr;
struct work work; struct work *work;
uint32_t res[MAXBUFFERS]; uint32_t res[MAXBUFFERS];
pthread_t pth; pthread_t pth;
int found; int found;
@ -182,10 +182,10 @@ struct pc_data {
static void send_scrypt_nonce(struct pc_data *pcd, uint32_t nonce) static void send_scrypt_nonce(struct pc_data *pcd, uint32_t nonce)
{ {
struct thr_info *thr = pcd->thr; struct thr_info *thr = pcd->thr;
struct work *work = &pcd->work; struct work *work = pcd->work;
if (scrypt_test(work->data, work->target, nonce)) if (scrypt_test(work->data, work->target, nonce))
submit_nonce(thr, &pcd->work, nonce); submit_nonce(thr, work, nonce);
else { else {
applog(LOG_INFO, "Scrypt error, review settings"); applog(LOG_INFO, "Scrypt error, review settings");
thr->cgpu->hw_errors++; thr->cgpu->hw_errors++;
@ -217,9 +217,10 @@ static void *postcalc_hash(void *userdata)
if (opt_scrypt) if (opt_scrypt)
send_scrypt_nonce(pcd, nonce); send_scrypt_nonce(pcd, nonce);
else else
submit_nonce(thr, &pcd->work, nonce); submit_nonce(thr, pcd->work, nonce);
} }
discard_work(pcd->work);
free(pcd); free(pcd);
return NULL; return NULL;
@ -234,7 +235,7 @@ void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res)
} }
pcd->thr = thr; pcd->thr = thr;
memcpy(&pcd->work, work, sizeof(struct work)); pcd->work = copy_work(work);
memcpy(&pcd->res, res, BUFFERSIZE); memcpy(&pcd->res, res, BUFFERSIZE);
if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) { if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {

1
miner.h

@ -1119,6 +1119,7 @@ extern int curses_int(const char *query);
extern char *curses_input(const char *query); extern char *curses_input(const char *query);
extern void kill_work(void); extern void kill_work(void);
extern void switch_pools(struct pool *selected); extern void switch_pools(struct pool *selected);
extern void discard_work(struct work *work);
extern void remove_pool(struct pool *pool); extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg); extern void write_config(FILE *fcfg);
extern void zero_bestshare(void); extern void zero_bestshare(void);

Loading…
Cancel
Save