njs_chb_destroy() frees chain nodes through chain->free() and guards
against a NULL free callback. njs_chb_drain() and the tail-freeing
path of njs_chb_drop() called njs_mp_free() directly, which is wrong
for chains initialized with NJS_CHB_CTX_INIT() where chain->free is
js_free(), and unsafe for NGX_CHB_CTX_INIT() chains where chain->free
is NULL.
Both paths now route through chain->free() with the same NULL guard
as njs_chb_destroy().
drain -= njs_chb_node_size(n);
chain->nodes = n->next;
- njs_mp_free(chain->pool, n);
+ if (chain->free != NULL) {
+ chain->free(chain->pool, n);
+ }
+
n = chain->nodes;
}
while (n != NULL) {
next = n->next;
- njs_mp_free(chain->pool, n);
+
+ if (chain->free != NULL) {
+ chain->free(chain->pool, n);
+ }
+
n = next;
}
}