From 330c966556a5edaea1ef50097b70a556534d3911 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 19 Jan 2015 21:42:25 +1100 Subject: [PATCH] Remove client ram safely in invalidate_client foreach loop --- src/connector.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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); }