- fix
[oweals/gnunet.git] / src / util / os_priority.c
index 2d5dba4a311ff8fd47387c64fd498ea352825163..b8b8549634ae66e3ad9bb4037637257c832db22d 100644 (file)
@@ -151,11 +151,22 @@ GNUNET_OS_install_parent_control_handler (void *cls,
     putenv (GNUNET_OS_CONTROL_PIPE "=");
     return;
   }
-  /* Gcc will issue a warning here. What to do with it? */
+#if !defined (WINDOWS)
+  if (pipe_fd >= FD_SETSIZE)
+#else
+  if ((FILE_TYPE_UNKNOWN == GetFileType ((HANDLE) (uintptr_t) pipe_fd))
+      && (0 != GetLastError ()))
+#endif
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", env_buf);
+    putenv (GNUNET_OS_CONTROL_PIPE "=");
+    return;
+  }
 #if WINDOWS
-  control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) pipe_fd);
+  control_pipe = GNUNET_DISK_get_handle_from_w32_handle ((HANDLE) (uintptr_t) pipe_fd);
 #else
-  control_pipe = GNUNET_DISK_get_handle_from_crt_fd ((int) pipe_fd);
+  control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
 #endif
   if (NULL == control_pipe)
   {
@@ -655,6 +666,7 @@ start_process (int pipe_control,
   {
     childpipe_read = NULL;
     childpipe_write = NULL;
+    childpipe_read_fd = -1;
   }
   if (NULL != pipe_stdout)
   {
@@ -730,6 +742,8 @@ start_process (int pipe_control,
     snprintf (fdbuf, 100, "%x", childpipe_read_fd);
     setenv (GNUNET_OS_CONTROL_PIPE, fdbuf, 1);
   }
+  else
+    unsetenv (GNUNET_OS_CONTROL_PIPE);
   if (NULL != pipe_stdin)
   {
     GNUNET_break (0 == close (fd_stdin_write));
@@ -1057,7 +1071,6 @@ start_process (int pipe_control,
       if (childpipe_write)
         GNUNET_DISK_file_close (childpipe_write);
       GNUNET_free (cmd);
-      GNUNET_free (path);
       return NULL;
     }
     /* Unlike *nix variant, we don't dup the handle, so can't close
@@ -1078,7 +1091,6 @@ start_process (int pipe_control,
     if (lsocks_pipe == NULL)
     {
       GNUNET_free (cmd);
-      GNUNET_free (path);
       GNUNET_DISK_pipe_close (lsocks_pipe);
       if (GNUNET_YES == pipe_control)
       {
@@ -1169,7 +1181,6 @@ start_process (int pipe_control,
 
   GNUNET_free (env_block);
   GNUNET_free (cmd);
-  GNUNET_free (path);
   free (wpath);
   free (wcmd);
   if (GNUNET_YES == pipe_control)