fixing leak
authorChristian Grothoff <christian@grothoff.org>
Mon, 5 Oct 2009 11:50:52 +0000 (11:50 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 5 Oct 2009 11:50:52 +0000 (11:50 +0000)
src/util/disk.c
src/util/disk.h
src/util/network.c
src/util/server.c

index a3d5db097fe2dc91d27e4fe41d8dc2dd4b1bcff9..ee327e03fbdad552fd08dcd7be115f793db8ca0f 100644 (file)
@@ -75,10 +75,7 @@ typedef struct
   int include_sym_links;
 } GetFileSizeData;
 
-struct GNUNET_DISK_PipeHandle
-{
-  struct GNUNET_DISK_FileHandle fd[2];
-};
+
 
 static int
 getSizeRec (void *ptr, const char *fn)
@@ -1500,6 +1497,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
 
 /**
  * Creates an interprocess channel
+ *
  * @param blocking creates an asynchronous pipe if set to GNUNET_NO
  * @return handle to the new pipe, NULL on error
  */
@@ -1516,12 +1514,15 @@ GNUNET_DISK_pipe (int blocking)
   int fd[2];
   int ret;
   int flags;
+  int eno;
 
   ret = pipe (fd);
   if (ret != -1)
     {
-      p->fd[0].fd = fd[0];
-      p->fd[1].fd = fd[1];
+      p->fd[0] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
+      p->fd[1] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
+      p->fd[0]->fd = fd[0];
+      p->fd[1]->fd = fd[1];
 
       if (!blocking)
         {
@@ -1536,10 +1537,14 @@ GNUNET_DISK_pipe (int blocking)
             }
           if (ret == -1)
             {
+             eno = errno;
               GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "fcntl");
-              close (fd[0]);
-              close (fd[1]);
+              GNUNET_DISK_file_close (p->fd[0]);
+              GNUNET_DISK_file_close (p->fd[1]);
+             p->fd[0] = NULL;
+             p->fd[1] = NULL;
               err = GNUNET_YES;
+             errno = eno;
             }
         }
     }
@@ -1556,8 +1561,10 @@ GNUNET_DISK_pipe (int blocking)
           DWORD mode;
 
           mode = PIPE_NOWAIT;
-          SetNamedPipeHandleState (p->fd[0].h, &mode, NULL, NULL);
-          SetNamedPipeHandleState (p->fd[1].h, &mode, NULL, NULL);
+         p->fd[0] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
+         p->fd[1] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle));
+          SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
+          SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
           /* this always fails on Windows 95, so we don't care about error handling */
         }
     }
@@ -1586,13 +1593,13 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
 {
   int ret = GNUNET_OK;
 #ifdef MINGW
-  if (!CloseHandle (p->fd[0].h))
+  if (!CloseHandle (p->fd[0]->h))
     {
       SetErrnoFromWinError (GetLastError ());
       ret = GNUNET_SYSERR;
     }
 
-  if (!CloseHandle (p->fd[1].h))
+  if (!CloseHandle (p->fd[1]->h))
     {
       SetErrnoFromWinError (GetLastError ());
       ret = GNUNET_SYSERR;
@@ -1600,7 +1607,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
 #else
   int save;
   
-  if (0 != close (p->fd[0].fd))
+  if (0 != close (p->fd[0]->fd))
     {
       ret = GNUNET_SYSERR;
       save = errno;
@@ -1608,11 +1615,13 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
   else
     save = 0;
   
-  if (0 != close (p->fd[1].fd))
+  if (0 != close (p->fd[1]->fd))
     ret = GNUNET_SYSERR;
   else
     errno = save;
 #endif
+  GNUNET_free (p->fd[0]);
+  GNUNET_free (p->fd[1]);
   GNUNET_free (p);
   return ret;
 }
@@ -1626,7 +1635,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
 const struct GNUNET_DISK_FileHandle *
 GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, int n)
 {
-  return &p->fd[n];
+  return p->fd[n];
 }
 
 /**
index 9857a0fed506e4849b09bccf0c7516ab9faedc4a..17ebe4a0a7e6918babf2b7fb7e8e1ddcb62cbe1c 100644 (file)
@@ -41,6 +41,7 @@ struct GNUNET_DISK_FileHandle
 \r
 /**\r
  * Retrieve OS file handle\r
+ *\r
  * @internal\r
  * @param fh GNUnet file descriptor\r
  * @param dst destination buffer\r
index 2e1d40c80a746fc0481c4141e43833efaa128ce8..2278ae34ba44cb504cf4e4840d2bb656cbc613e6 100644 (file)
@@ -155,11 +155,11 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
   SetErrnoFromWinsockError (WSAGetLastError ());  \r
 #else\r
   ret = close (desc->fd);\r
-#endif\r
+#endif  \r
   eno = errno;\r
   GNUNET_free (desc);\r
   errno = eno;\r
-  return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;\r
+  return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;\r
 }\r
 \r
 /**\r
index 303c370db1c5037a563c0ec01e6149345ea8183f..a2d5551a4120c680c424b2cf5e61122f2541990e 100644 (file)
@@ -459,11 +459,9 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
         return NULL;
     }
   ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
-  ret->shutpipe = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileDescriptor *[2]));
   if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO)))
     {
       GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsock));
-      GNUNET_free (ret->shutpipe);
       GNUNET_free (ret);
       return NULL;
     }