accept() leaks memory on windows due to incorrect ordering of
[p5sagit/p5-mst-13.2.git] / win32 / win32sck.c
index 2e4dc77..043ad44 100644 (file)
@@ -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 *