From: Gurusamy Sarathy Date: Mon, 10 Jul 2000 07:06:00 +0000 (+0000) Subject: accept() leaks memory on windows due to incorrect ordering of X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e94524934c1af4124b2888d9716e5304ee50ad9;p=p5sagit%2Fp5-mst-13.2.git accept() leaks memory on windows due to incorrect ordering of closesocket() and fclose() calls p4raw-id: //depot/perl@6328 --- diff --git a/win32/win32sck.c b/win32/win32sck.c index 2e4dc77..043ad44 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -143,7 +143,7 @@ my_fdopen(int fd, char *mode) /* * If we get here, then fd is actually a socket. */ - Newz(1310, fp, 1, FILE); + Newz(1310, fp, 1, FILE); /* XXX leak, good thing this code isn't used */ if(fp == NULL) { errno = ENOMEM; return NULL; @@ -422,18 +422,19 @@ win32_socket(int af, int type, int protocol) int my_fclose (FILE *pf) { - int osf, retval; + int osf; if (!wsock_started) /* No WinSock? */ return(fclose(pf)); /* Then not a socket. */ osf = TO_SOCKET(fileno(pf));/* Get it now before it's gone! */ - retval = fclose(pf); /* Must fclose() before closesocket() */ if (osf != -1 && closesocket(osf) == SOCKET_ERROR && WSAGetLastError() != WSAENOTSOCK) { + (void)fclose(pf); return EOF; } - return retval; + else + return fclose(pf); } struct hostent *