From d61ba33e69efeaa4476c93dc952e50ef86728a25 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 15 Feb 2015 22:44:24 +1100 Subject: [PATCH] Set subproxy count and subid under lock to prevent clashes and ensure the subproxy inherits the parent's id --- src/generator.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/generator.c b/src/generator.c index 8307ab39..1f44fbad 100644 --- a/src/generator.c +++ b/src/generator.c @@ -914,7 +914,6 @@ static bool recruit_subproxy(gdata_t *gdata, proxy_instance_t *proxi); static void add_subproxy(proxy_instance_t *proxi, proxy_instance_t *subproxy) { mutex_lock(&proxi->proxy_lock); - proxi->subproxy_count++; HASH_ADD(sh, proxi->subproxies, subid, sizeof(int), subproxy); proxi->client_headroom += proxi->clients_per_proxy; mutex_unlock(&proxi->proxy_lock); @@ -1618,7 +1617,12 @@ static proxy_instance_t *create_subproxy(gdata_t *gdata, proxy_instance_t *proxi subproxy->cs->ckp = subproxy->ckp = proxi->ckp; subproxy->si = proxi->si; - subproxy->subid = proxi->subproxy_count; + + mutex_lock(&proxi->proxy_lock); + subproxy->subid = ++proxi->subproxy_count; + mutex_unlock(&proxi->proxy_lock); + + subproxy->id = proxi->id; subproxy->auth = proxi->auth; subproxy->pass = proxi->pass; subproxy->parent = proxi;