mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-06-08 11:08:19 +02:00
sysdeps-unix: Don't leak struct addrinfo on OOM during connect()
If we ran out of memory while handling connect() errors, we didn't
free the linked list of struct addrinfo. Move their cleanup to the
"out" phase of the function so that we always do it.
While I'm there, change the iterator variable tmp to be const, to make
it more obvious that we aren't meant to free it.
This is similar to commit 00badeba (!143) in the corresponding Windows
code path, but with some refactoring.
Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
041cadb738
commit
682e619196
1 changed files with 5 additions and 3 deletions
|
|
@ -1411,7 +1411,8 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
|
|||
DBusSocket fd = DBUS_SOCKET_INIT;
|
||||
int res;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *ai, *tmp;
|
||||
struct addrinfo *ai = NULL;
|
||||
const struct addrinfo *tmp;
|
||||
DBusError *connect_error;
|
||||
|
||||
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
|
||||
|
|
@ -1450,7 +1451,6 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
|
|||
{
|
||||
if (!_dbus_open_socket (&fd.fd, tmp->ai_family, SOCK_STREAM, 0, error))
|
||||
{
|
||||
freeaddrinfo(ai);
|
||||
_DBUS_ASSERT_ERROR_IS_SET(error);
|
||||
_dbus_socket_invalidate (&fd);
|
||||
goto out;
|
||||
|
|
@ -1491,7 +1491,6 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
|
|||
|
||||
break;
|
||||
}
|
||||
freeaddrinfo(ai);
|
||||
|
||||
if (!_dbus_socket_is_valid (fd))
|
||||
{
|
||||
|
|
@ -1523,6 +1522,9 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
|
|||
}
|
||||
|
||||
out:
|
||||
if (ai != NULL)
|
||||
freeaddrinfo (ai);
|
||||
|
||||
while ((connect_error = _dbus_list_pop_first (&connect_errors)))
|
||||
{
|
||||
dbus_error_free (connect_error);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue