From 99d15342327cdc1f9d6fb06ded4e77c3820df5e6 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Tue, 21 Apr 2020 22:42:42 +0200 Subject: Wg-user: Free sockets on error and eof --- sysdep/unix/wg_user.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sysdep/unix/wg_user.c b/sysdep/unix/wg_user.c index 4668b2c6..5f5428bf 100644 --- a/sysdep/unix/wg_user.c +++ b/sysdep/unix/wg_user.c @@ -55,9 +55,7 @@ void user_err_hook(struct birdsock *bs, int err) /* return; */ log(L_TRACE "WG: ERR %p %d %s", bs, err, bs->err); - if (bs->fd >= 0) - close(bs->fd); - bs->fd = -1; + rfree(bs); } static void @@ -223,7 +221,10 @@ wg_user_set_device(struct pool *pool, int res = sk_connect_unix(sock, path); DBG(L_TRACE "WG: socket %d %d %s", res, sock->fd, path); if (res < 0) - return -1; + { + rfree(sock); + return -1; + } uint tbsize = 8192; sk_set_tbsize(sock, tbsize); @@ -236,7 +237,7 @@ wg_user_set_device(struct pool *pool, if (len < 0) { - /* FIXME close */ + rfree(sock); return -1; } res = sk_send(sock, tbsize - size); -- cgit v1.2.3