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

examples/dvbinfo/tcp.c: Resource leak (CID 17269)

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 63c868ec
......@@ -126,7 +126,7 @@ int tcp_open(const char *ipaddress, int port)
sflags = SOCK_CLOEXEC;
#endif
s_ctl = socket(ptr->ai_family, ptr->ai_socktype | sflags, ptr->ai_protocol);
if (s_ctl <= 0)
if (s_ctl < 0)
{
perror("tcp socket error");
continue;
......@@ -136,6 +136,7 @@ int tcp_open(const char *ipaddress, int port)
if (!set_fdsocketclosexec(s_ctl))
{
close(s_ctl);
s_ctl = -1;
continue;
}
#endif
......@@ -146,6 +147,7 @@ int tcp_open(const char *ipaddress, int port)
if (result < 0)
{
close(s_ctl);
s_ctl = -1;
perror( "tcp connect error" );
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