Skip to content

Commit

Permalink
Close socket when setsockopt fails
Browse files Browse the repository at this point in the history
- Prevent resource leak
  • Loading branch information
visuve committed Mar 4, 2021
1 parent cd40b23 commit 468159e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/packet_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 468159e

Please sign in to comment.