Fix memory leaks (#18564)

This commit is contained in:
saumyamukul 2018-08-06 00:17:08 -06:00 committed by leda
parent cddcf545db
commit dfa0360d99
2 changed files with 7 additions and 0 deletions

View File

@ -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;

View File

@ -255,6 +255,7 @@ private:
std::mutex _closeMutex;
std::condition_variable _closeCondition;
std::vector<char*> _protocolNames;
enum class CloseState
{