From 81abb3f17f9ffa9eef1945939abef6c26b56e1ec Mon Sep 17 00:00:00 2001 Message-Id: <81abb3f17f9ffa9eef1945939abef6c26b56e1ec.1714736800.git.mdw@distorted.org.uk> From: Mark Wooding Date: Mon, 1 Jun 2020 12:28:31 +0100 Subject: [PATCH] lib/addr.c: Introduce our own `freeaddrinfo' function. Organization: Straylight/Edgeware From: Mark Wooding I plan to return fake `struct addrinfo' lists from `netaddress_resolve', but I can't make one which can be freed using `freeaddrinfo''s secret recipe, so I must make my own veneer. --- lib/addr.c | 10 ++++++++++ lib/addr.h | 1 + lib/client-common.c | 2 +- server/state.c | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/addr.c b/lib/addr.c index 1b62251..a02a965 100644 --- a/lib/addr.c +++ b/lib/addr.c @@ -339,6 +339,9 @@ void netaddress_format(const struct netaddress *na, * @param passive True if passive (bindable) address is desired * @param protocol Protocol number desired (e.g. @c IPPROTO_TCP) * @return List of suitable addresses or NULL + * + * Free the address using netaddress_freeaddrinfo() because it might not + * have come from getaddrinfo() directly. */ struct addrinfo *netaddress_resolve(const struct netaddress *na, int passive, @@ -364,6 +367,13 @@ struct addrinfo *netaddress_resolve(const struct netaddress *na, return res; } +/** @brief Free an address-info list from netaddress_resovle() + * @param res Address-info list + */ +void netaddress_freeaddrinfo(struct addrinfo *res) { + freeaddrinfo(res); +} + /* Local Variables: c-basic-offset:2 diff --git a/lib/addr.h b/lib/addr.h index 385259d..c0e82b0 100644 --- a/lib/addr.h +++ b/lib/addr.h @@ -65,6 +65,7 @@ void netaddress_format(const struct netaddress *na, struct addrinfo *netaddress_resolve(const struct netaddress *na, int passive, int protocol) attribute((nonnull (1))); +void netaddress_freeaddrinfo(struct addrinfo *res) attribute((nonnull (1))); #endif /* ADDR_H */ diff --git a/lib/client-common.c b/lib/client-common.c index ead7d2e..f344159 100644 --- a/lib/client-common.c +++ b/lib/client-common.c @@ -98,7 +98,7 @@ socklen_t disorder_find_server(struct config *c, unsigned flags, if(namep) *namep = format_sockaddr(sa); if(res) - freeaddrinfo(res); + netaddress_freeaddrinfo(res); return len; } diff --git a/server/state.c b/server/state.c index 11b21f6..63c7c45 100644 --- a/server/state.c +++ b/server/state.c @@ -171,7 +171,7 @@ void reset_sockets(ev_source *ev) { } /* if res is still set it needs freeing */ if(res) - freeaddrinfo(res); + netaddress_freeaddrinfo(res); } /** @brief Reconfigure the server -- [mdw]