From 77a1b4e058520aa2eed2dfc2f2dfac560e9309c5 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 19 Mar 2020 17:03:11 +0000 Subject: [PATCH] lws_set_wsi_user: allow setting to override existing internal allocation --- lib/core-net/wsi.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/core-net/wsi.c b/lib/core-net/wsi.c index 78e086e51..46566100b 100644 --- a/lib/core-net/wsi.c +++ b/lib/core-net/wsi.c @@ -637,14 +637,11 @@ lws_wsi_user(struct lws *wsi) void lws_set_wsi_user(struct lws *wsi, void *data) { - /* client and user owns it... */ - if (wsi->user_space_externally_allocated || - /* server, and protocol can never own it, user can control it... */ - (wsi->protocol && !wsi->protocol->per_session_data_size)) - wsi->user_space = data; - else - lwsl_err("%s: Cannot set internally-allocated user_space\n", - __func__); + if (!wsi->user_space_externally_allocated && wsi->user_space) + lws_free(wsi->user_space); + + wsi->user_space_externally_allocated = 1; + wsi->user_space = data; } struct lws *