[libdvbpsi-devel] examples/dvbinfo/udp.c: Resource leak (CID 17268)
Jean-Paul Saman
git at videolan.org
Wed Apr 16 15:53:32 CEST 2014
libdvbpsi | branch: master | Jean-Paul Saman <jpsaman at videolan.org> | Fri Apr 11 15:26:14 2014 +0200| [d74e30d9d9216fc4899b2a92a90c9217da873a6c] | committer: 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.
> http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=d74e30d9d9216fc4899b2a92a90c9217da873a6c
---
examples/dvbinfo/udp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/examples/dvbinfo/udp.c b/examples/dvbinfo/udp.c
index b37e0a9..1c23fe7 100644
--- a/examples/dvbinfo/udp.c
+++ b/examples/dvbinfo/udp.c
@@ -247,7 +247,7 @@ int udp_open(const char *interface, 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("udp socket error");
continue;
@@ -257,6 +257,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
if (!set_fdsocketclosexec(s_ctl))
{
close(s_ctl);
+ s_ctl = -1;
continue;
}
#endif
@@ -274,6 +275,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
if (result < 0)
{
close(s_ctl);
+ s_ctl = -1;
perror("udp bind error");
continue;
}
@@ -283,6 +285,7 @@ int udp_open(const char *interface, const char *ipaddress, int port)
mcast_connect(s_ctl, NULL, saddr, ptr->ai_addrlen))
{
close(s_ctl);
+ s_ctl = -1;
perror("mcast connect error");
continue;
}
More information about the libdvbpsi-devel
mailing list