summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-03-29 06:08:57 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-03-29 06:08:57 +0000
commitbc8b3cebc31677b216d67f98ec276782260d02ab (patch)
tree9b4b5d577df4ed2cf18d80ac8af4aea3b36ab3bf /lib
parent4868478e9eb4b9063f86a5f05cf3284107e506ac (diff)
in svcudp_bufcreate(), only close socket if we created it
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/rpc/svc_udp.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c
index 7f7d2d7397d..cebc4a0c89e 100644
--- a/lib/libc/rpc/svc_udp.c
+++ b/lib/libc/rpc/svc_udp.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: svc_udp.c,v 1.5 1997/02/17 00:04:00 deraadt Exp $";
+static char *rcsid = "$OpenBSD: svc_udp.c,v 1.6 1997/03/29 06:08:56 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -98,6 +98,7 @@ svcudp_bufcreate(sock, sendsz, recvsz)
register int sock;
u_int sendsz, recvsz;
{
+ bool_t madesock = FALSE;
register SVCXPRT *xprt;
register struct svcudp_data *su;
struct sockaddr_in addr;
@@ -108,6 +109,7 @@ svcudp_bufcreate(sock, sendsz, recvsz)
perror("svcudp_create: socket creation problem");
return ((SVCXPRT *)NULL);
}
+ madesock = TRUE;
}
memset(&addr, 0, sizeof (addr));
addr.sin_len = sizeof(struct sockaddr_in);
@@ -118,26 +120,30 @@ svcudp_bufcreate(sock, sendsz, recvsz)
}
if (getsockname(sock, (struct sockaddr *)&addr, &len) != 0) {
perror("svcudp_create - cannot getsockname");
- (void)close(sock);
+ if (madesock)
+ (void)close(sock);
return ((SVCXPRT *)NULL);
}
xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
if (xprt == NULL) {
(void)fprintf(stderr, "svcudp_create: out of memory\n");
- (void)close(sock);
+ if (madesock)
+ (void)close(sock);
return (NULL);
}
su = (struct svcudp_data *)mem_alloc(sizeof(*su));
if (su == NULL) {
(void)fprintf(stderr, "svcudp_create: out of memory\n");
- (void)close(sock);
+ if (madesock)
+ (void)close(sock);
free(xprt);
return (NULL);
}
su->su_iosz = ((MAX(sendsz, recvsz) + 3) / 4) * 4;
if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL) {
(void)fprintf(stderr, "svcudp_create: out of memory\n");
- (void)close(sock);
+ if (madesock)
+ (void)close(sock);
free(xprt);
free(su);
return (NULL);