WPS SSDP: Fix socket leaks on error paths

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-07-07 13:01:45 +03:00
parent 19991e5fb2
commit a5ed45586c

View file

@ -866,20 +866,24 @@ int ssdp_open_multicast_sock(u32 ip_addr)
return -1; return -1;
#if 0 /* maybe ok if we sometimes block on writes */ #if 0 /* maybe ok if we sometimes block on writes */
if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0) if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0) {
close(sd);
return -1; return -1;
}
#endif #endif
if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF, if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF,
&ip_addr, sizeof(ip_addr))) { &ip_addr, sizeof(ip_addr))) {
wpa_printf(MSG_DEBUG, "WPS: setsockopt(IP_MULTICAST_IF) %x: " wpa_printf(MSG_DEBUG, "WPS: setsockopt(IP_MULTICAST_IF) %x: "
"%d (%s)", ip_addr, errno, strerror(errno)); "%d (%s)", ip_addr, errno, strerror(errno));
close(sd);
return -1; return -1;
} }
if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_TTL, if (setsockopt(sd, IPPROTO_IP, IP_MULTICAST_TTL,
&ttl, sizeof(ttl))) { &ttl, sizeof(ttl))) {
wpa_printf(MSG_DEBUG, "WPS: setsockopt(IP_MULTICAST_TTL): " wpa_printf(MSG_DEBUG, "WPS: setsockopt(IP_MULTICAST_TTL): "
"%d (%s)", errno, strerror(errno)); "%d (%s)", errno, strerror(errno));
close(sd);
return -1; return -1;
} }
@ -898,6 +902,7 @@ int ssdp_open_multicast_sock(u32 ip_addr)
"WPS UPnP: setsockopt " "WPS UPnP: setsockopt "
"IP_ADD_MEMBERSHIP errno %d (%s)", "IP_ADD_MEMBERSHIP errno %d (%s)",
errno, strerror(errno)); errno, strerror(errno));
close(sd);
return -1; return -1;
} }
} }