Skip to content

Commit

Permalink
Fix memory leaks affecting getblocktemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
pooler committed Mar 15, 2016
1 parent 426fe09 commit aa07150
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ static bool gbt_work_decode(const json_t *val, struct work *work)
goto out;
}
sha256d(merkle_tree[1 + i], tx, tx_size);
free(tx);
if (!submit_coinbase)
strcat(work->txs, tx_hex);
}
Expand Down Expand Up @@ -604,7 +605,7 @@ static bool gbt_work_decode(const json_t *val, struct work *work)
if (!have_longpoll) {
char *lp_uri;
tmp = json_object_get(val, "longpolluri");
lp_uri = json_is_string(tmp) ? strdup(json_string_value(tmp)) : rpc_url;
lp_uri = strdup(json_is_string(tmp) ? json_string_value(tmp) : rpc_url);
have_longpoll = true;
tq_push(thr_info[longpoll_thr_id].q, lp_uri);
}
Expand Down Expand Up @@ -1115,6 +1116,7 @@ static void *miner_thread(void *userdata)
if (!have_stratum &&
(time(NULL) - g_work_time >= min_scantime ||
work.data[19] >= end_nonce)) {
work_free(&g_work);
if (unlikely(!get_work(mythr, &g_work))) {
applog(LOG_ERR, "work retrieval failed, exiting "
"mining thread %d", mythr->id);
Expand Down

1 comment on commit aa07150

@solardiz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change on line 608 here actually fixes a use-after-free, which was a much worse issue than a memory leak. Maybe this should be documented in NEWS for 2.4.4 in the current tree (2.5.0+) - better late than never? (Just spent some time troubleshooting this on an older fork of cpuminer. Proper documentation of this fix would have saved me time.)

Please sign in to comment.