Skip to content

Commit e42a42a

Browse files
committed
[LibWebsocketServer] Clang - Fix memory management for URI in eventCallback
Signed-off-by: Thomas BRUNEL <[email protected]>
1 parent f217547 commit e42a42a

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/websockets/libwebsockets/LibWebsocketServer.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,8 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
312312
if (strcmp("websocket", static_cast<char*>(in)) == 0)
313313
{
314314
// Check URI
315-
#ifdef _MSC_VER
316-
char uri[512u];
317-
#else // _MSC_VER
318-
char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
319-
#endif // _MSC_VER
320-
int uri_len = lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI);
315+
char* uri = new char[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
316+
int uri_len = lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI);
321317
if ((uri_len >= static_cast<int>(server->m_url.path().size())) &&
322318
(strncmp(uri, server->m_url.path().c_str(), server->m_url.path().size()) == 0))
323319
{
@@ -423,6 +419,7 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
423419
lwsl_err("invalid URI\n");
424420
ret = -1;
425421
}
422+
delete[] uri;
426423
}
427424
else
428425
{
@@ -442,16 +439,13 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
442439
server->m_clients[wsi] = client;
443440

444441
// Notify connection
445-
#ifdef _MSC_VER
446-
char uri[512u];
447-
#else // _MSC_VER
448-
char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
449-
#endif // _MSC_VER
442+
char* uri = new char[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
450443
if (lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI) <= 0)
451444
{
452445
uri[0] = 0;
453446
}
454447
server->m_listener->wsClientConnected(uri, client);
448+
delete[] uri;
455449
}
456450
break;
457451

0 commit comments

Comments
 (0)