From be9b402aa3c68eb5c86fe8954c4a4c6a251685f0 Mon Sep 17 00:00:00 2001 From: Daniel Caujolle-Bert Date: Wed, 31 Mar 2021 13:35:37 +0200 Subject: [PATCH] Fix nasty bug in UDPSocket::close(). --- UDPSocket.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 510c8a2..ab025ec 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -187,6 +187,8 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std return false; } + close(index); + int fd = ::socket(addr.ss_family, SOCK_DGRAM, 0); if (fd < 0) { #if defined(_WIN32) || defined(_WIN64) @@ -343,13 +345,13 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s void CUDPSocket::close() { - for (int i = 0; i < UDP_SOCKET_MAX; i++) - close(m_fd[i]); + for (unsigned int i = 0; i < UDP_SOCKET_MAX; i++) + close(i); } void CUDPSocket::close(const unsigned int index) { - if (m_fd[index] >= 0) { + if ((index < UDP_SOCKET_MAX) && (m_fd[index] >= 0)) { #if defined(_WIN32) || defined(_WIN64) ::closesocket(m_fd[index]); #else