diff --git a/src/lb_chash.c b/src/lb_chash.c index 0bf4e81a2..23448df80 100644 --- a/src/lb_chash.c +++ b/src/lb_chash.c @@ -84,8 +84,13 @@ static inline void chash_queue_dequeue_srv(struct server *s) * increased the weight beyond the original weight */ if (s->lb_nodes_tot < s->next_eweight) { - struct tree_occ *new_nodes = realloc(s->lb_nodes, s->next_eweight * sizeof(*new_nodes)); + struct tree_occ *new_nodes; + /* First we need to remove all server's entries from its tree + * because the realloc will change all nodes pointers */ + chash_dequeue_srv(s); + + new_nodes = realloc(s->lb_nodes, s->next_eweight * sizeof(*new_nodes)); if (new_nodes) { unsigned int j; @@ -494,7 +499,6 @@ void chash_init_server_tree(struct proxy *p) srv->lb_nodes_tot = srv->uweight * BE_WEIGHT_SCALE; srv->lb_nodes_now = 0; srv->lb_nodes = calloc(srv->lb_nodes_tot, sizeof(struct tree_occ)); - for (node = 0; node < srv->lb_nodes_tot; node++) { srv->lb_nodes[node].server = srv; srv->lb_nodes[node].node.key = full_hash(srv->puid * SRV_EWGHT_RANGE + node);