Skip to content

Commit da4cc63

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

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/websockets/libwebsockets/LibWebsocketServer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
313313
{
314314
// Check URI
315315
#ifdef _MSC_VER
316-
char uri[512u];
316+
char* uri = new char[512u];
317317
#else // _MSC_VER
318-
char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
318+
char* uri = new char[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
319319
#endif // _MSC_VER
320320
int uri_len = lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI);
321321
if ((uri_len >= static_cast<int>(server->m_url.path().size())) &&
@@ -423,6 +423,7 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
423423
lwsl_err("invalid URI\n");
424424
ret = -1;
425425
}
426+
delete[] uri;
426427
}
427428
else
428429
{
@@ -443,15 +444,16 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
443444

444445
// Notify connection
445446
#ifdef _MSC_VER
446-
char uri[512u];
447+
char* uri = new char[512u];
447448
#else // _MSC_VER
448-
char uri[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
449+
char* uri = new char[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
449450
#endif // _MSC_VER
450451
if (lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI) <= 0)
451452
{
452453
uri[0] = 0;
453454
}
454455
server->m_listener->wsClientConnected(uri, client);
456+
delete[] uri;
455457
}
456458
break;
457459

0 commit comments

Comments
 (0)