diff --git a/cocos/network/WebSocket.cpp b/cocos/network/WebSocket.cpp index 6e8568a1eb..c9c45a7fe2 100644 --- a/cocos/network/WebSocket.cpp +++ b/cocos/network/WebSocket.cpp @@ -570,6 +570,11 @@ WebSocket::~WebSocket() CC_SAFE_DELETE(__wsHelper); } + for(auto name:_protocolNames){ + free(name); + } + free(_lwsProtocols); + Director::getInstance()->getEventDispatcher()->removeEventListener(_resetDirectorListener); *_isDestroyed = true; @@ -601,6 +606,7 @@ bool WebSocket::init(const Delegate& delegate, _lwsProtocols[i].callback = WebSocketCallbackWrapper::onSocketCallback; size_t nameLen = protocols->at(i).length(); char* name = (char*)malloc(nameLen + 1); + _protocolNames.push_back(name); name[nameLen] = '\0'; strcpy(name, protocols->at(i).c_str()); _lwsProtocols[i].name = name; diff --git a/cocos/network/WebSocket.h b/cocos/network/WebSocket.h index e70d26a370..f939944d00 100644 --- a/cocos/network/WebSocket.h +++ b/cocos/network/WebSocket.h @@ -255,6 +255,7 @@ private: std::mutex _closeMutex; std::condition_variable _closeCondition; + std::vector _protocolNames; enum class CloseState {