From 7239565b0fea8504deebc5bd43c4fa1ea80fcb17 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Mon, 2 Nov 2020 13:11:49 -0600 Subject: [PATCH] rx: Reorganize LWP rxi_Sendmsg to use 'goto error' Our LWP version of rxi_Sendmsg can allocate an fd_set, but we don't free the fd_set if sendmsg() returns certain errors afterwards. To make sure we go through the same cleanup code for the different possible error code paths, reorganize the function to go through a 'goto error'-style destructor. This also makes our return codes a bit more consistent; we should always return -errno now for errors. Change-Id: I5eaeb7f4ea1d76acc3bd9c52dc258f53f59f631e Reviewed-on: https://gerrit.openafs.org/14422 Reviewed-by: Mark Vitale Tested-by: BuildBot Reviewed-by: Cheyenne Wills Reviewed-by: Benjamin Kaduk --- src/rx/rx_lwp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/rx/rx_lwp.c b/src/rx/rx_lwp.c index a64f3be..f3378de 100644 --- a/src/rx/rx_lwp.c +++ b/src/rx/rx_lwp.c @@ -430,9 +430,9 @@ rxi_Recvmsg(osi_socket socket, struct msghdr *msg_p, int flags) int rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) { + int err = 0; fd_set *sfds = (fd_set *) 0; while (sendmsg(socket, msg_p, flags) == -1) { - int err; #ifdef AFS_NT40_ENV err = WSAGetLastError(); @@ -447,7 +447,8 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) if (!(sfds = IOMGR_AllocFDSet())) { (osi_Msg "rx failed to alloc fd_set: "); perror("rx_sendmsg"); - return -1; + err = ENOMEM; + goto error; } FD_SET(socket, sfds); } @@ -469,9 +470,7 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) { (osi_Msg "rx failed to send packet: "); perror("rx_sendmsg"); - if (err > 0) - return -err; - return -1; + goto error; } while ((err = select( #ifdef AFS_NT40_ENV @@ -489,5 +488,12 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) if (sfds) IOMGR_FreeFDSet(sfds); return 0; + + error: + if (sfds) + IOMGR_FreeFDSet(sfds); + if (err > 0) + return -err; + return -1; } #endif -- 1.9.4