lws_dll[2]_foreach_safe: add user cb param

The callback flow is a bit more disruptive than doing the iteration
directly in your function.  This helps by passing a user void *
into the callback set as an lws_dll[2]_foreach_safe() arg.
diff --git a/include/libwebsockets/lws-misc.h b/include/libwebsockets/lws-misc.h
index 7e2e26e..c6b7b7c 100644
--- a/include/libwebsockets/lws-misc.h
+++ b/include/libwebsockets/lws-misc.h
@@ -213,7 +213,8 @@
 /* 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_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 d57da56..074e1fa 100644
--- a/lib/core-net/close.c
+++ b/lib/core-net/close.c
@@ -120,7 +120,7 @@
 
 #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 @@
 		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 25af8d7..80e1d48 100644
--- a/lib/core/libwebsockets.c
+++ b/lib/core/libwebsockets.c
@@ -263,10 +263,11 @@
 
 
 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 @@
 }
 
 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 26e4f65..6247bdb 100644
--- a/lib/roles/ws/ops-ws.c
+++ b/lib/roles/ws/ops-ws.c
@@ -1978,9 +1978,23 @@
 	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;