From 57b75b336c22b9665b219b3c7495a42967aa49cd Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Thu, 12 Sep 2019 15:51:56 +0200 Subject: [PATCH] [core] Free addrinfo if bind fails. Fixes #657 --- srtcore/channel.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index 8f0fa9cf1..3f3cbc322 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -167,8 +167,11 @@ void CChannel::open(const sockaddr* addr) throw CUDTException(MJ_SETUP, MN_NORES, NET_ERROR); // On Windows ai_addrlen has type size_t (unsigned), while bind takes int. - if (0 != ::bind(m_iSocket, res->ai_addr, (socklen_t) res->ai_addrlen)) - throw CUDTException(MJ_SETUP, MN_NORES, NET_ERROR); + if (0 != ::bind(m_iSocket, res->ai_addr, (socklen_t)res->ai_addrlen)) + { + ::freeaddrinfo(res); + throw CUDTException(MJ_SETUP, MN_NORES, NET_ERROR); + } memcpy(&m_BindAddr, res->ai_addr, res->ai_addrlen); m_BindAddr.len = (socklen_t) res->ai_addrlen;