From 468159e6d2687243fcd6c647986d0c747192e19d Mon Sep 17 00:00:00 2001 From: visuve Date: Thu, 4 Mar 2021 23:55:29 +0200 Subject: [PATCH] Close socket when setsockopt fails - Prevent resource leak --- src/packet_sender.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index c7a91e21..96f7649e 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -267,6 +267,11 @@ void PacketSender::open_l3_socket(SocketType type) { #endif const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP; if (setsockopt(sockfd, level, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) { + #ifndef _WIN32 + ::close(sockfd); + #else + ::closesocket(sockfd); + #endif throw socket_open_error(make_error_string()); }