Browse Source

Fix potential memleak when stratum_add_send is unable to send to a queue.

master
Con Kolivas 8 years ago
parent
commit
3dfe7b95e3
  1. 6
      src/ckpool.c
  2. 2
      src/ckpool.h
  3. 5
      src/stratifier.c

6
src/ckpool.c

@ -203,7 +203,7 @@ ckmsgq_t *create_ckmsgqs(ckpool_t *ckp, const char *name, const void *func, cons
/* Generic function for adding messages to a ckmsgq linked list and signal the
* ckmsgq parsing thread(s) to wake up and process it. */
void _ckmsgq_add(ckmsgq_t *ckmsgq, void *data, const char *file, const char *func, const int line)
bool _ckmsgq_add(ckmsgq_t *ckmsgq, void *data, const char *file, const char *func, const int line)
{
ckmsg_t *msg;
@ -212,7 +212,7 @@ void _ckmsgq_add(ckmsgq_t *ckmsgq, void *data, const char *file, const char *fun
/* Discard data if we're unlucky enough to be sending it to
* msg queues not set up during start up */
free(data);
return;
return false;
}
while (unlikely(!ckmsgq->active))
cksleep_ms(10);
@ -225,6 +225,8 @@ void _ckmsgq_add(ckmsgq_t *ckmsgq, void *data, const char *file, const char *fun
DL_APPEND(ckmsgq->msgs, msg);
pthread_cond_broadcast(ckmsgq->cond);
mutex_unlock(ckmsgq->lock);
return true;
}
/* Return whether there are any messages queued in the ckmsgq linked list. */

2
src/ckpool.h

@ -326,7 +326,7 @@ static const char __maybe_unused *stratum_msgs[] = {
ckmsgq_t *create_ckmsgq(ckpool_t *ckp, const char *name, const void *func);
ckmsgq_t *create_ckmsgqs(ckpool_t *ckp, const char *name, const void *func, const int count);
void _ckmsgq_add(ckmsgq_t *ckmsgq, void *data, const char *file, const char *func, const int line);
bool _ckmsgq_add(ckmsgq_t *ckmsgq, void *data, const char *file, const char *func, const int line);
#define ckmsgq_add(ckmsgq, data) _ckmsgq_add(ckmsgq, data, __FILE__, __func__, __LINE__)
bool ckmsgq_empty(ckmsgq_t *ckmsgq);
unix_msg_t *get_unix_msg(proc_instance_t *pi);

5
src/stratifier.c

@ -3082,7 +3082,10 @@ static void stratum_add_send(sdata_t *sdata, json_t *val, const int64_t client_i
msg = ckzalloc(sizeof(smsg_t));
msg->json_msg = val;
msg->client_id = client_id;
ckmsgq_add(sdata->ssends, msg);
if (likely(ckmsgq_add(sdata->ssends, msg)))
return;
json_decref(msg->json_msg);
free(msg);
}
static void drop_client(ckpool_t *ckp, sdata_t *sdata, const int64_t id)

Loading…
Cancel
Save