Merge pull request #963 from kebby/master
authorMarek Safar <marek.safar@gmail.com>
Tue, 18 Mar 2014 12:45:38 +0000 (13:45 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 18 Mar 2014 12:45:38 +0000 (13:45 +0100)
Fix Process.CancelErrorRead

1  2 
mcs/class/System/System.Diagnostics/Process.cs

index 7a63ce0377c62529dbf33b5f8c9718d401f74ff9,515903d3fe01c610e607cc0d12e3fab7167d6d8b..af427037b285cfc9ae8e1b4e7aa7183d1fddc04b
@@@ -918,7 -918,8 +918,7 @@@ namespace System.Diagnostics 
                                                                  IntPtr stderr,
                                                                  ref ProcInfo proc_info);
  
 -              private static bool Start_shell (ProcessStartInfo startInfo,
 -                                               Process process)
 +              private static bool Start_shell (ProcessStartInfo startInfo, Process process)
                {
                        ProcInfo proc_info=new ProcInfo();
                        bool ret;
  
                        process.process_handle = proc_info.process_handle;
                        process.pid = proc_info.pid;
 -
                        process.StartExitCallbackIfNeeded ();
 -
                        return(ret);
                }
  
                        if (startInfo == null)
                                throw new ArgumentNullException ("startInfo");
  
 -                      Process process=new Process();
 +                      Process process = new Process();
                        process.StartInfo = startInfo;
 -                      if (Start_common(startInfo, process))
 +                      if (Start_common(startInfo, process) && process.process_handle != IntPtr.Zero)
                                return process;
                        return null;
                }
                [ComVisibleAttribute(false)] 
                public void CancelErrorRead ()
                {
-                       if (process_handle == IntPtr.Zero || output_stream == null || StartInfo.RedirectStandardOutput == false)
-                               throw new InvalidOperationException ("Standard output has not been redirected or process has not been started.");
+                       if (process_handle == IntPtr.Zero || error_stream == null || StartInfo.RedirectStandardError == false)
+                               throw new InvalidOperationException ("Standard error has not been redirected or process has not been started.");
  
                        if ((async_mode & AsyncModes.SyncOutput) != 0)
                                throw new InvalidOperationException ("OutputStream is not enabled for asynchronous read operations.");
                                                        async_output.Close ();
                                                if (async_error != null)
                                                        async_error.Close ();
 +
 +                                              if (input_stream != null) {
 +                                                      input_stream.Close();
 +                                                      input_stream = null;
 +                                              }
 +
 +                                              if (output_stream != null) {
 +                                                      output_stream.Close();
 +                                                      output_stream = null;
 +                                              }
 +
 +                                              if (error_stream != null) {
 +                                                      error_stream.Close();
 +                                                      error_stream = null;
 +                                              }
                                        }
                                }
                                
                                                Process_free_internal(process_handle);
                                                process_handle=IntPtr.Zero;
                                        }
 -
 -                                      if (input_stream != null) {
 -                                              input_stream.Close();
 -                                              input_stream = null;
 -                                      }
 -
 -                                      if (output_stream != null) {
 -                                              output_stream.Close();
 -                                              output_stream = null;
 -                                      }
 -
 -                                      if (error_stream != null) {
 -                                              error_stream.Close();
 -                                              error_stream = null;
 -                                      }
                                }
                        }
                        base.Dispose (disposing);