summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-02-17 00:04:01 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-02-17 00:04:01 +0000
commitb74b87e3f0be8aad8511cc6f47cff43f8fff01ec (patch)
tree0a436aff64c0bf6d33e880d4a9ef00bb740cb133 /lib
parent85f8f05d1a2f560f8a2b89c5d4b324625ffab2f7 (diff)
do not leak descriptors and mem
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/rpc/svc_tcp.c14
-rw-r--r--lib/libc/rpc/svc_udp.c13
2 files changed, 15 insertions, 12 deletions
diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c
index d1250271d02..80aacb5ae21 100644
--- a/lib/libc/rpc/svc_tcp.c
+++ b/lib/libc/rpc/svc_tcp.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: svc_tcp.c,v 1.11 1997/02/13 22:33:13 deraadt Exp $";
+static char *rcsid = "$OpenBSD: svc_tcp.c,v 1.12 1997/02/17 00:03:57 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -129,7 +129,6 @@ svctcp_create(sock, sendsize, recvsize)
u_int sendsize;
u_int recvsize;
{
- bool_t madesock = FALSE;
register SVCXPRT *xprt;
register struct tcp_rendezvous *r;
struct sockaddr_in addr;
@@ -140,7 +139,6 @@ svctcp_create(sock, sendsize, recvsize)
perror("svctcp_.c - udp socket creation problem");
return ((SVCXPRT *)NULL);
}
- madesock = TRUE;
}
memset(&addr, 0, sizeof (addr));
addr.sin_len = sizeof(struct sockaddr_in);
@@ -152,20 +150,22 @@ svctcp_create(sock, sendsize, recvsize)
if ((getsockname(sock, (struct sockaddr *)&addr, &len) != 0) ||
(listen(sock, 2) != 0)) {
perror("svctcp_.c - cannot getsockname or listen");
- if (madesock)
- (void)close(sock);
+ (void)close(sock);
return ((SVCXPRT *)NULL);
}
r = (struct tcp_rendezvous *)mem_alloc(sizeof(*r));
if (r == NULL) {
- (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ (void)fprintf(stderr, "svctcp_create: out of memory\n");
+ (void)close(sock);
return (NULL);
}
r->sendsize = sendsize;
r->recvsize = recvsize;
xprt = (SVCXPRT *)mem_alloc(sizeof(SVCXPRT));
if (xprt == NULL) {
- (void) fprintf(stderr, "svctcp_create: out of memory\n");
+ (void)fprintf(stderr, "svctcp_create: out of memory\n");
+ (void)close(sock);
+ free(r);
return (NULL);
}
xprt->xp_p2 = NULL;
diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c
index 1b3da18094b..7f7d2d7397d 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.4 1996/09/15 09:31:42 tholo Exp $";
+static char *rcsid = "$OpenBSD: svc_udp.c,v 1.5 1997/02/17 00:04:00 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -98,7 +98,6 @@ 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;
@@ -109,7 +108,6 @@ 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);
@@ -120,23 +118,28 @@ svcudp_bufcreate(sock, sendsz, recvsz)
}
if (getsockname(sock, (struct sockaddr *)&addr, &len) != 0) {
perror("svcudp_create - cannot getsockname");
- if (madesock)
- (void)close(sock);
+ (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);
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);
+ 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);
+ free(xprt);
+ free(su);
return (NULL);
}
xdrmem_create(