mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Close socket when setsockopt fails
- Prevent resource leak
This commit is contained in:
@@ -267,6 +267,11 @@ void PacketSender::open_l3_socket(SocketType type) {
|
|||||||
#endif
|
#endif
|
||||||
const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP;
|
const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP;
|
||||||
if (setsockopt(sockfd, level, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) {
|
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());
|
throw socket_open_error(make_error_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user