Commit d74e30d9 authored by Jean-Paul Saman's avatar Jean-Paul Saman

examples/dvbinfo/udp.c: Resource leak (CID 17268)

The code does not leak a socket descriptor while looping over addrinfo pointer structs.However initializing s_ctl to -1 again after calling close(s_ctl) is good practise.
parent f70707bb
...@@ -247,7 +247,7 @@ int udp_open(const char *interface, const char *ipaddress, int port) ...@@ -247,7 +247,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
sflags = SOCK_CLOEXEC; sflags = SOCK_CLOEXEC;
#endif #endif
s_ctl = socket(ptr->ai_family, ptr->ai_socktype | sflags, ptr->ai_protocol); s_ctl = socket(ptr->ai_family, ptr->ai_socktype | sflags, ptr->ai_protocol);
if (s_ctl <= 0) if (s_ctl < 0)
{ {
perror("udp socket error"); perror("udp socket error");
continue; continue;
...@@ -257,6 +257,7 @@ int udp_open(const char *interface, const char *ipaddress, int port) ...@@ -257,6 +257,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
if (!set_fdsocketclosexec(s_ctl)) if (!set_fdsocketclosexec(s_ctl))
{ {
close(s_ctl); close(s_ctl);
s_ctl = -1;
continue; continue;
} }
#endif #endif
...@@ -274,6 +275,7 @@ int udp_open(const char *interface, const char *ipaddress, int port) ...@@ -274,6 +275,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
if (result < 0) if (result < 0)
{ {
close(s_ctl); close(s_ctl);
s_ctl = -1;
perror("udp bind error"); perror("udp bind error");
continue; continue;
} }
...@@ -283,6 +285,7 @@ int udp_open(const char *interface, const char *ipaddress, int port) ...@@ -283,6 +285,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
mcast_connect(s_ctl, NULL, saddr, ptr->ai_addrlen)) mcast_connect(s_ctl, NULL, saddr, ptr->ai_addrlen))
{ {
close(s_ctl); close(s_ctl);
s_ctl = -1;
perror("mcast connect error"); perror("mcast connect error");
continue; continue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment