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>
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);
{
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;
break;
}
- freeaddrinfo(ai);
if (!_dbus_socket_is_valid (fd))
{
}
out:
+ if (ai != NULL)
+ freeaddrinfo (ai);
+
while ((connect_error = _dbus_list_pop_first (&connect_errors)))
{
dbus_error_free (connect_error);