Browse Source

Fix a memory leak and some compiler warnings in oclvanityminer.

master
samr7 13 years ago
parent
commit
d717f45f41
  1. 49
      oclvanityminer.c

49
oclvanityminer.c

@ -208,7 +208,7 @@ server_workitem_add(server_request_t *reqp, workitem_t *wip)
} }
static int static size_t
server_body_reader(const char *buf, size_t elemsize, size_t len, void *param) server_body_reader(const char *buf, size_t elemsize, size_t len, void *param)
{ {
server_request_t *reqp = (server_request_t *) param; server_request_t *reqp = (server_request_t *) param;
@ -235,14 +235,14 @@ server_body_reader(const char *buf, size_t elemsize, size_t len, void *param)
if (reqp->part_size > (1024*1024)) { if (reqp->part_size > (1024*1024)) {
fprintf(stderr, "Line too long from server"); fprintf(stderr, "Line too long from server");
reqp->request_status = 0; reqp->request_status = 0;
return -1; return 0;
} }
} }
reqp->part_buf = (char *) realloc(reqp->part_buf, reqp->part_buf = (char *) realloc(reqp->part_buf,
reqp->part_size); reqp->part_size);
if (!reqp->part_buf) { if (!reqp->part_buf) {
fprintf(stderr, "Out of memory"); fprintf(stderr, "Out of memory");
return -1; return 0;
} }
} }
@ -329,13 +329,25 @@ free_work_array(workitem_t **workarray, workitem_t *except)
} }
} }
workitem_t ** void
server_context_getwork(server_context_t *ctxp) server_request_free(server_request_t *reqp)
{
if (reqp->part_buf != NULL)
free(reqp->part_buf);
if (reqp->items)
free_work_array(reqp->items, NULL);
free(reqp);
}
int
server_context_getwork(server_context_t *ctxp, workitem_t ***arrayret)
{ {
CURLcode res; CURLcode res;
server_request_t *reqp; server_request_t *reqp;
CURL *creq; CURL *creq;
*arrayret = NULL;
reqp = (server_request_t *) malloc(sizeof(*reqp)); reqp = (server_request_t *) malloc(sizeof(*reqp));
memset(reqp, 0, sizeof(*reqp)); memset(reqp, 0, sizeof(*reqp));
@ -352,22 +364,23 @@ server_context_getwork(server_context_t *ctxp)
} }
res = curl_easy_perform(creq); res = curl_easy_perform(creq);
curl_easy_cleanup(creq);
if (res != CURLE_OK) { if (res != CURLE_OK) {
fprintf(stderr, "Get work request failed: %s\n", fprintf(stderr, "Get work request failed: %s\n",
curl_easy_strerror(res)); curl_easy_strerror(res));
curl_easy_cleanup(creq); server_request_free(reqp);
free_work_array(reqp->items, NULL); return -1;
return NULL;
} }
if (reqp->items) { if (reqp->items) {
reqp->items[reqp->nitems] = NULL;
qsort(reqp->items, reqp->nitems, sizeof(*(reqp->items)), qsort(reqp->items, reqp->nitems, sizeof(*(reqp->items)),
server_workitem_ptr_comp); server_workitem_ptr_comp);
reqp->items[reqp->nitems] = NULL; *arrayret = reqp->items;
} }
curl_easy_cleanup(creq); return 0;
return reqp->items;
} }
@ -519,7 +532,7 @@ main(int argc, char **argv)
server_context_t *scp = NULL; server_context_t *scp = NULL;
workitem_t *wip = NULL, **wipa; workitem_t *wip = NULL, **wipa;
int wip_index; int wip_index = 0;
int was_sleeping = 0; int was_sleeping = 0;
struct timeval tv; struct timeval tv;
@ -550,11 +563,12 @@ main(int argc, char **argv)
break; break;
case 'i': case 'i':
interval = atoi(optarg); interval = atoi(optarg);
if (interval < 60) { if (interval < 10) {
fprintf(stderr, fprintf(stderr,
"Invalid interval '%s'\n", optarg); "Invalid interval '%s'\n", optarg);
return 1; return 1;
} }
break;
case 'p': case 'p':
platformidx = atoi(optarg); platformidx = atoi(optarg);
break; break;
@ -651,9 +665,13 @@ main(int argc, char **argv)
scp->verbose = verbose; scp->verbose = verbose;
wipa = NULL; wipa = NULL;
/* Get the initial bounty list, abort on failure */
if (server_context_getwork(scp, &wipa))
return 1;
while (1) { while (1) {
if (!wipa) { if (!wipa || !wipa[wip_index]) {
wipa = server_context_getwork(scp); server_context_getwork(scp, &wipa);
wip_index = 0; wip_index = 0;
} }
@ -727,6 +745,7 @@ main(int argc, char **argv)
sleepy.tv_sec += interval; sleepy.tv_sec += interval;
pthread_mutex_lock(&soln_lock); pthread_mutex_lock(&soln_lock);
res = 0;
if (!soln_private_key) if (!soln_private_key)
res = pthread_cond_timedwait(&soln_cond, res = pthread_cond_timedwait(&soln_cond,
&soln_lock, &sleepy); &soln_lock, &sleepy);

Loading…
Cancel
Save