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 <mvitale@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
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();
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);
}
{
(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
if (sfds)
IOMGR_FreeFDSet(sfds);
return 0;
+
+ error:
+ if (sfds)
+ IOMGR_FreeFDSet(sfds);
+ if (err > 0)
+ return -err;
+ return -1;
}
#endif