From a3d124b989b2e638ca9ad839753e90eca4b436a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Thu, 7 May 1998 20:35:55 -0700
Subject: [PATCH] handle leak fixed

Rev: src/fdlib.c:1.19
---
 src/fdlib.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/fdlib.c b/src/fdlib.c
index 2243cfd2b1..a0859bc92a 100644
--- a/src/fdlib.c
+++ b/src/fdlib.c
@@ -3,7 +3,7 @@
 #include "error.h"
 #include <math.h>
 
-RCSID("$Id: fdlib.c,v 1.18 1998/05/06 00:33:20 hubbe Exp $");
+RCSID("$Id: fdlib.c,v 1.19 1998/05/08 03:35:55 hubbe Exp $");
 
 #ifdef HAVE_WINSOCK_H
 
@@ -350,16 +350,32 @@ SOCKFUN1(listen, int)
 
 int fd_close(FD fd)
 {
-  HANDLE h;
+  long h;
+  int type;
   mt_lock(&fd_mutex);
   h=(HANDLE)da_handle[fd];
   FDDEBUG(fprintf(stderr,"Closing %d (%d)\n",fd,da_handle[fd]));
+  type=fd_type[fd];
   mt_unlock(&fd_mutex);
-  if(!CloseHandle(h))
+  switch(type)
   {
-    errno=GetLastError();
-    return -1;
+    case FD_SOCKET:
+      if(closesocket((SOCKET)h))
+      {
+	errno=GetLastError();
+	FDDEBUG(fprintf(stderr,"Closing %d (%d) failed with errno=%d\n",fd,da_handle[fd],errno));
+	return -1;
+      }
+      break;
+
+    default:
+      if(!CloseHandle((HANDLE)h))
+      {
+	errno=GetLastError();
+	return -1;
+      }
   }
+  FDDEBUG(fprintf(stderr,"%d (%d) closed\n",fd,da_handle[fd]));
   mt_lock(&fd_mutex);
   if(fd_type[fd]<FD_NO_MORE_FREE)
   {
-- 
GitLab