Browse Source

Handle present but drop tagged client properly and don't leak the smsg ram

master
Con Kolivas 10 years ago
parent
commit
44c990a589
  1. 31
      src/stratifier.c

31
src/stratifier.c

@ -3305,6 +3305,12 @@ static void parse_method(sdata_t *sdata, stratum_instance_t *client, const int64
return; return;
} }
static void free_smsg(smsg_t *msg)
{
json_decref(msg->json_msg);
free(msg);
}
/* Entered with client holding ref count */ /* Entered with client holding ref count */
static void parse_instance_msg(sdata_t *sdata, smsg_t *msg, stratum_instance_t *client) static void parse_instance_msg(sdata_t *sdata, smsg_t *msg, stratum_instance_t *client)
{ {
@ -3339,8 +3345,7 @@ static void parse_instance_msg(sdata_t *sdata, smsg_t *msg, stratum_instance_t *
} }
parse_method(sdata, client, client_id, id_val, method, params, msg->address); parse_method(sdata, client, client_id, id_val, method, params, msg->address);
out: out:
json_decref(val); free_smsg(msg);
free(msg);
} }
static void srecv_process(ckpool_t *ckp, char *buf) static void srecv_process(ckpool_t *ckp, char *buf)
@ -3395,10 +3400,10 @@ static void srecv_process(ckpool_t *ckp, char *buf)
client = __instance_by_id(sdata, msg->client_id); client = __instance_by_id(sdata, msg->client_id);
/* If client_id instance doesn't exist yet, create one */ /* If client_id instance doesn't exist yet, create one */
if (unlikely(!client)) { if (unlikely(!client)) {
noid = true; if (likely(!__dropped_instance(sdata, msg->client_id))) {
if (likely(!__dropped_instance(sdata, msg->client_id))) noid = true;
client = __stratum_add_instance(ckp, msg->client_id, server); client = __stratum_add_instance(ckp, msg->client_id, server);
else } else
dropped = true; dropped = true;
} else if (unlikely(client->dropped)) } else if (unlikely(client->dropped))
dropped = true; dropped = true;
@ -3406,15 +3411,15 @@ static void srecv_process(ckpool_t *ckp, char *buf)
__inc_instance_ref(client); __inc_instance_ref(client);
ck_wunlock(&sdata->instance_lock); ck_wunlock(&sdata->instance_lock);
if (unlikely(noid)) { if (unlikely(dropped)) {
if (unlikely(dropped)) { /* Client may be NULL here */
/* Client may be NULL here */ LOGNOTICE("Stratifier skipped dropped instance %ld message server %d",
LOGNOTICE("Stratifier skipped dropped instance %ld message server %d", msg->client_id, server);
msg->client_id, server); free_smsg(msg);
goto out; goto out;
}
LOGINFO("Stratifier added instance %ld server %d", client->id, server);
} }
if (unlikely(noid))
LOGINFO("Stratifier added instance %ld server %d", client->id, server);
parse_instance_msg(sdata, msg, client); parse_instance_msg(sdata, msg, client);
dec_instance_ref(sdata, client); dec_instance_ref(sdata, client);

Loading…
Cancel
Save