summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-02-03 17:59:07 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-11-02 15:19:30 +0000
commitec350d8d06f5b55fa42834f4d651ea9018e02650 (patch)
tree456df5140e35b3423bd7db622e1b0dfbbef202c5
parent93e9941de6908f731e3f9b0fac1083f0e9a47dd5 (diff)
downloaddbus-ec350d8d06f5b55fa42834f4d651ea9018e02650.tar.gz
_dbus_listen_tcp_socket: avoid leaking listen_fd in unlikely circumstances
If getaddrinfo (with port == 0) succeeds, the kernel gives us a port when we first listen on a socket, we jump back to redo_lookup_with_port, and getaddrinfo (with the nonzero port) fails, we leak listen_fd and all the fds in it. From the department of "without static analysis we'd never have spotted this", or possibly "backward goto considered harmful". Bug: https://bugs.freedesktop.org/show_bug.cgi?id=29881 Bug-NB: NB#180486 CID-2389 Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
-rw-r--r--dbus/dbus-sysdeps-unix.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index f51f6fcb..98667f24 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -1331,13 +1331,14 @@ _dbus_listen_tcp_socket (const char *host,
hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
redo_lookup_with_port:
+ ai = NULL;
if ((res = getaddrinfo(host, port, &hints, &ai)) != 0 || !ai)
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
"Failed to lookup host/port: \"%s:%s\": %s (%d)",
host ? host : "*", port, gai_strerror(res), res);
- return -1;
+ goto failed;
}
tmp = ai;