Skip to content

Commit

Permalink
tools/nut-scanner/scan_xml_http.c: close broadcast socket too, avoid …
Browse files Browse the repository at this point in the history
…FD leak [networkupstools#2511]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 10, 2024
1 parent fc1bc0d commit e820654
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/nut-scanner/scan_xml_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void * nutscan_scan_xml_http_thready(void * arg)
/* A NULL "ip" causes a broadcast scan; otherwise the single ip address is queried directly */
char *ip = NULL;
useconds_t usec_timeout = 0;
int peerSocket;
int peerSocket = -1;
int sockopt_on = 1;
struct sockaddr_in sockAddress_udp;
socklen_t sockAddressLength = sizeof(sockAddress_udp);
Expand Down Expand Up @@ -433,7 +433,8 @@ static void * nutscan_scan_xml_http_thready(void * arg)
(ip ? ip : "<broadcast>"));

end:
if (ip != NULL)
/* Broadcast is also a socket! */
if (peerSocket != -1)
close(peerSocket);

end_free:
Expand Down

0 comments on commit e820654

Please sign in to comment.