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) ...@@ -126,7 +126,7 @@ int tcp_open(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("tcp socket error"); perror("tcp socket error");
continue; continue;
...@@ -136,6 +136,7 @@ int tcp_open(const char *ipaddress, int port) ...@@ -136,6 +136,7 @@ int tcp_open(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
...@@ -146,6 +147,7 @@ int tcp_open(const char *ipaddress, int port) ...@@ -146,6 +147,7 @@ int tcp_open(const char *ipaddress, int port)
if (result < 0) if (result < 0)
{ {
close(s_ctl); close(s_ctl);
s_ctl = -1;
perror( "tcp connect error" ); perror( "tcp 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