From: deraadt Date: Sat, 29 Mar 1997 06:08:56 +0000 (+0000) Subject: in svcudp_bufcreate(), only close socket if we created it X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=76d3f26e3706fd0da393f800dbd8442e72ac36f1;p=openbsd in svcudp_bufcreate(), only close socket if we created it --- 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);