From 51f886cb02bc99c56bf9106cc948ce8f316aef1f Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Tue, 6 Nov 2018 18:29:47 +0100 Subject: [PATCH] Fixed memory leak --- .../SmingCore/Network/Http/Websocket/WebsocketResource.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sming/SmingCore/Network/Http/Websocket/WebsocketResource.cpp b/Sming/SmingCore/Network/Http/Websocket/WebsocketResource.cpp index c89cf494f5..3fe349f503 100644 --- a/Sming/SmingCore/Network/Http/Websocket/WebsocketResource.cpp +++ b/Sming/SmingCore/Network/Http/Websocket/WebsocketResource.cpp @@ -24,6 +24,11 @@ WebsocketResource::~WebsocketResource() int WebsocketResource::checkHeaders(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response) { WebsocketConnection* socket = new WebsocketConnection(&connection, false); + if(!socket) { + debug_e("Unable to create websocket connection"); + return 1; + } + socket->setBinaryHandler(wsBinary); socket->setMessageHandler(wsMessage); socket->setConnectionHandler(wsConnect); @@ -35,7 +40,7 @@ int WebsocketResource::checkHeaders(HttpServerConnection& connection, HttpReques } connection.setTimeOut(USHRT_MAX); //Disable disconnection on connection idle (no rx/tx) - + connection.userData = (void *)socket; connection.setUpgradeCallback(std::bind(&WebsocketConnection::onConnected, socket)); // TODO: Re-Enable Command Executor...