diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp index 1b54c2cce2253389e29a7fd2f542c5ebcb1bd77a..b4e9f40407c1e3d30abab8380526ea88af3ae25f 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp @@ -80,6 +80,8 @@ static Status DeleteForwardPortWithHdc(std::pair remote_s if (log) log->Printf("Delete port forwarding %d -> %s, device=%s", local_port, remote_socket_name.c_str(), device_id.c_str()); + if (!socket_namespace) + return Status("Invalid socket namespace"); HdcClient hdc(device_id); return hdc.DeletePortForwarding(local_port, remote_socket_name, *socket_namespace); @@ -108,10 +110,10 @@ static Status FindUnusedPort(uint16_t &port) { PlatformOHOSRemoteGDBServer::PlatformOHOSRemoteGDBServer() {} PlatformOHOSRemoteGDBServer::~PlatformOHOSRemoteGDBServer() { - for (const auto &it : m_port_forwards){ + for (const auto &it : m_port_forwards) { DeleteForwardPortWithHdc(it.second, m_device_id); } - for (const auto &it_socket : m_remote_socket_name){ + for (const auto &it_socket : m_remote_socket_name) { DeleteForwardPortWithHdc(it_socket.second, m_socket_namespace, m_device_id); } } @@ -193,7 +195,7 @@ void PlatformOHOSRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) { auto it = m_port_forwards.find(pid); auto it_socket = m_remote_socket_name.find(pid); - if (it != m_port_forwards.end() && it->second.second != 0){ + if (it != m_port_forwards.end() && it->second.second != 0) { const auto error = DeleteForwardPortWithHdc(it->second, m_device_id); if (error.Fail()) { if (log) @@ -205,7 +207,7 @@ void PlatformOHOSRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) { m_port_forwards.erase(it); } - if(it_socket != m_remote_socket_name.end()){ + if(it_socket != m_remote_socket_name.end()) { const auto error_Socket = DeleteForwardPortWithHdc(it_socket->second, m_socket_namespace, m_device_id); if (error_Socket.Fail()) { if (log)