diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp index 632785cffc..8b3e7042d8 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp @@ -268,7 +268,8 @@ WebSocketCloseTest::WebSocketCloseTest() if (!_wsiTest->init(*this, "ws://echo.websocket.org")) { - CC_SAFE_DELETE(_wsiTest); + delete _wsiTest; + _wsiTest = nullptr; } auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, [](Ref* sender){ @@ -289,6 +290,12 @@ WebSocketCloseTest::WebSocketCloseTest() addChild(notifyLabel, 1); } +WebSocketCloseTest::~WebSocketCloseTest() +{ + if (_wsiTest) + _wsiTest->close(); +} + // Delegate methods void WebSocketCloseTest::onOpen(network::WebSocket* ws) { @@ -303,7 +310,8 @@ void WebSocketCloseTest::onMessage(network::WebSocket* ws, const network::WebSoc void WebSocketCloseTest::onClose(network::WebSocket* ws) { log("websocket (%p) closed.", ws); - CC_SAFE_DELETE(ws); + delete ws; + _wsiTest = nullptr; } void WebSocketCloseTest::onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error) diff --git a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h index 45cc8fce35..8f50a7cc83 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/NetworkTest/WebSocketTest.h @@ -64,6 +64,7 @@ public: virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error)override; WebSocketCloseTest(); + ~WebSocketCloseTest(); virtual std::string title() const override { return "WebSocket close by resetDirector event Test"; } std::string subtitle() const override { return "Click close button, Program should close without crash."; }