Skip to content

Commit c08b41a

Browse files
committed
Fix nasty bug in UDPSocket::close().
1 parent 6b43bce commit c08b41a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

UDPSocket.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
188188
return false;
189189
}
190190

191+
close(index);
192+
191193
int fd = ::socket(addr.ss_family, SOCK_DGRAM, 0);
192194
if (fd < 0) {
193195
#if defined(_WIN32) || defined(_WIN64)
@@ -344,13 +346,13 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s
344346

345347
void CUDPSocket::close()
346348
{
347-
for (int i = 0; i < UDP_SOCKET_MAX; i++)
348-
close(m_fd[i]);
349+
for (unsigned int i = 0; i < UDP_SOCKET_MAX; i++)
350+
close(i);
349351
}
350352

351353
void CUDPSocket::close(const unsigned int index)
352354
{
353-
if (m_fd[index] >= 0) {
355+
if ((index < UDP_SOCKET_MAX) && (m_fd[index] >= 0)) {
354356
#if defined(_WIN32) || defined(_WIN64)
355357
::closesocket(m_fd[index]);
356358
#else

0 commit comments

Comments
 (0)