diff --git a/include/libwebsockets/lws-misc.h b/include/libwebsockets/lws-misc.h index 7e2e26e9f..c6b7b7cec 100644 --- a/include/libwebsockets/lws-misc.h +++ b/include/libwebsockets/lws-misc.h @@ -213,7 +213,8 @@ lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead); /* another way to do lws_start_foreach_dll_safe() on a list via a cb */ LWS_VISIBLE LWS_EXTERN int -lws_dll_foreach_safe(struct lws_dll *phead, int (*cb)(struct lws_dll *d)); +lws_dll_foreach_safe(struct lws_dll *phead, void *user, + int (*cb)(struct lws_dll *d, void *user)); #define lws_dll_is_detached(___dll, __head) \ (!(___dll)->prev && !(___dll)->next && (__head)->prev != (___dll)) @@ -274,7 +275,8 @@ LWS_VISIBLE LWS_EXTERN void lws_dll2_remove(struct lws_dll2 *d); LWS_VISIBLE LWS_EXTERN int -lws_dll2_foreach_safe(struct lws_dll2_owner *owner, int (*cb)(struct lws_dll2 *d)); +lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, + int (*cb)(struct lws_dll2 *d, void *user)); /* * these are safe against the current container object getting deleted, diff --git a/lib/core-net/close.c b/lib/core-net/close.c index d57da564d..074e1fac0 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -120,7 +120,7 @@ lws_remove_child_from_any_parent(struct lws *wsi) #if !defined(LWS_NO_CLIENT) static int -lws_close_trans_q_leader(struct lws_dll2 *d) +lws_close_trans_q_leader(struct lws_dll2 *d, void *user) { struct lws *w = lws_container_of(d, struct lws, dll2_cli_txn_queue); @@ -165,7 +165,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, if ((int)reason != -1) lws_vhost_lock(wsi->vhost); - lws_dll2_foreach_safe(&wsi->dll2_cli_txn_queue_owner, + lws_dll2_foreach_safe(&wsi->dll2_cli_txn_queue_owner, NULL, lws_close_trans_q_leader); /* diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index 25af8d790..80e1d485f 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -263,10 +263,11 @@ lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead) int -lws_dll_foreach_safe(struct lws_dll *phead, int (*cb)(struct lws_dll *d)) +lws_dll_foreach_safe(struct lws_dll *phead, void *user, + int (*cb)(struct lws_dll *d, void *user)) { lws_start_foreach_dll_safe(struct lws_dll *, p, tp, phead->next) { - if (cb(p)) + if (cb(p, user)) return 1; } lws_end_foreach_dll_safe(p, tp); @@ -274,10 +275,11 @@ lws_dll_foreach_safe(struct lws_dll *phead, int (*cb)(struct lws_dll *d)) } int -lws_dll2_foreach_safe(struct lws_dll2_owner *owner, int (*cb)(struct lws_dll2 *d)) +lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, + int (*cb)(struct lws_dll2 *d, void *user)) { lws_start_foreach_dll_safe(struct lws_dll2 *, p, tp, owner->head) { - if (cb(p)) + if (cb(p, user)) return 1; } lws_end_foreach_dll_safe(p, tp); diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 26e4f657c..6247bdbeb 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -1978,9 +1978,23 @@ rops_destroy_vhost_ws(struct lws_vhost *vh) return 0; } +#if defined(LWS_WITH_HTTP_PROXY) +static int +ws_destroy_proxy_buf(struct lws_dll *d, void *user) +{ + lws_free(d); + + return 0; +} +#endif + static int rops_destroy_role_ws(struct lws *wsi) { +#if defined(LWS_WITH_HTTP_PROXY) + lws_dll_foreach_safe(&wsi->ws->proxy_head, NULL, ws_destroy_proxy_buf); +#endif + lws_free_set_NULL(wsi->ws); return 0;