gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r9123 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r9123 - gnunet/src/util
Date: Mon, 5 Oct 2009 05:50:52 -0600

Author: grothoff
Date: 2009-10-05 05:50:52 -0600 (Mon, 05 Oct 2009)
New Revision: 9123

Modified:
   gnunet/src/util/disk.c
   gnunet/src/util/disk.h
   gnunet/src/util/network.c
   gnunet/src/util/server.c
Log:
fixing leak

Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c      2009-10-05 11:31:56 UTC (rev 9122)
+++ gnunet/src/util/disk.c      2009-10-05 11:50:52 UTC (rev 9123)
@@ -75,11 +75,8 @@
   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 @@
 
 /**
  * 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 @@
   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 @@
             }
           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 @@
           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 @@
 {
   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 @@
 #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 @@
   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 @@
 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];
 }
 
 /**

Modified: gnunet/src/util/disk.h
===================================================================
--- gnunet/src/util/disk.h      2009-10-05 11:31:56 UTC (rev 9122)
+++ gnunet/src/util/disk.h      2009-10-05 11:50:52 UTC (rev 9123)
@@ -41,6 +41,7 @@
 
 /**
  * Retrieve OS file handle
+ *
  * @internal
  * @param fh GNUnet file descriptor
  * @param dst destination buffer

Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2009-10-05 11:31:56 UTC (rev 9122)
+++ gnunet/src/util/network.c   2009-10-05 11:50:52 UTC (rev 9123)
@@ -155,11 +155,11 @@
   SetErrnoFromWinsockError (WSAGetLastError ());  
 #else
   ret = close (desc->fd);
-#endif
+#endif  
   eno = errno;
   GNUNET_free (desc);
   errno = eno;
-  return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
+  return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
 }
 
 /**

Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c    2009-10-05 11:31:56 UTC (rev 9122)
+++ gnunet/src/util/server.c    2009-10-05 11:50:52 UTC (rev 9123)
@@ -459,11 +459,9 @@
         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;
     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]