diff --git a/src/connector.c b/src/connector.c index c23173e1..6c89b02c 100644 --- a/src/connector.c +++ b/src/connector.c @@ -238,7 +238,7 @@ static void stratifier_drop_client(ckpool_t *ckp, int64_t id) * count. */ static void invalidate_client(ckpool_t *ckp, cdata_t *cdata, client_instance_t *client) { - client_instance_t *tmp; + client_instance_t *tmp, *client_delete = NULL; drop_client(cdata, client); if (ckp->passthrough) @@ -249,12 +249,15 @@ static void invalidate_client(ckpool_t *ckp, cdata_t *cdata, client_instance_t * * counts for them. */ ck_wlock(&cdata->lock); LL_FOREACH_SAFE(cdata->dead_clients, client, tmp) { + /* Don't free client ram when loop may still access it */ + dealloc(client_delete); if (!client->ref) { LL_DELETE(cdata->dead_clients, client); LOGINFO("Connector discarding client %ld", client->id); - free(client); + client_delete = client; } } + dealloc(client_delete); ck_wunlock(&cdata->lock); }