diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2014-04-29 22:18:49 +0400 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2014-04-29 22:19:09 +0400 |
commit | 07c92c51160f73465407548646747f4b8fc70531 (patch) | |
tree | 84baa6c50f0f34881962ce2fdcee4d30136c5e27 /main/src/addins/MonoDevelop.Autotools | |
parent | 1e9795afb101952b7ee9e1bbc08e6e257e717060 (diff) |
Fix leaks caused by ProcessWrapper and ChainedTextWriters.
Diffstat (limited to 'main/src/addins/MonoDevelop.Autotools')
-rw-r--r-- | main/src/addins/MonoDevelop.Autotools/MakefileProjectServiceExtension.cs | 40 | ||||
-rw-r--r-- | main/src/addins/MonoDevelop.Autotools/SolutionDeployer.cs | 60 |
2 files changed, 55 insertions, 45 deletions
diff --git a/main/src/addins/MonoDevelop.Autotools/MakefileProjectServiceExtension.cs b/main/src/addins/MonoDevelop.Autotools/MakefileProjectServiceExtension.cs index 8bbfc36f51..5c71be9a49 100644 --- a/main/src/addins/MonoDevelop.Autotools/MakefileProjectServiceExtension.cs +++ b/main/src/addins/MonoDevelop.Autotools/MakefileProjectServiceExtension.cs @@ -163,24 +163,28 @@ namespace MonoDevelop.Autotools string baseDir = project.BaseDirectory; string args = string.Format ("-j {0} {1}", data.ParallelProcesses, data.BuildTargetName); - StringWriter swOutput = new StringWriter (); - LogTextWriter chainedOutput = new LogTextWriter (); - chainedOutput.ChainWriter (monitor.Log); - chainedOutput.ChainWriter (swOutput); - - ProcessWrapper process = Runtime.ProcessService.StartProcess ("make", - args, - baseDir, - chainedOutput, - chainedOutput, - null); - process.WaitForOutput (); - - exitCode = process.ExitCode; - output = swOutput.ToString (); - chainedOutput.Close (); - swOutput.Close (); - monitor.Step ( 1 ); + using (var swOutput = new StringWriter ()) { + using (var chainedOutput = new LogTextWriter ()) { + chainedOutput.ChainWriter (monitor.Log); + chainedOutput.ChainWriter (swOutput); + + using (ProcessWrapper process = Runtime.ProcessService.StartProcess ("make", + args, + baseDir, + chainedOutput, + chainedOutput, + null)) { + process.WaitForOutput (); + + chainedOutput.UnchainWriter (monitor.Log); + chainedOutput.UnchainWriter (swOutput); + + exitCode = process.ExitCode; + output = swOutput.ToString (); + monitor.Step ( 1 ); + } + } + } } catch ( Exception e ) { diff --git a/main/src/addins/MonoDevelop.Autotools/SolutionDeployer.cs b/main/src/addins/MonoDevelop.Autotools/SolutionDeployer.cs index 9d95424cdd..3bb43a271b 100644 --- a/main/src/addins/MonoDevelop.Autotools/SolutionDeployer.cs +++ b/main/src/addins/MonoDevelop.Autotools/SolutionDeployer.cs @@ -178,33 +178,39 @@ namespace MonoDevelop.Autotools monitor.Step ( 1 ); - StringWriter sw = new StringWriter (); - LogTextWriter chainedOutput = new LogTextWriter (); - chainedOutput.ChainWriter (monitor.Log); - chainedOutput.ChainWriter (sw); - - ProcessWrapper process = Runtime.ProcessService.StartProcess ( "make", - "dist", - baseDir, - chainedOutput, - monitor.Log, - null ); - process.WaitForOutput (); - - if ( process.ExitCode > 0 ) - throw new Exception ( GettextCatalog.GetString ("An unspecified error occurred while running '{0}'", "make dist") ); - - monitor.Step ( 1 ); - - // FIXME: hackish way to get the created tarball's filename - string output = sw.ToString(); - int targz = output.LastIndexOf ( "tar.gz" ); - int begin = output.LastIndexOf ( '>', targz ); - - string filename = output.Substring ( begin + 1, (targz - begin) + 5 ).Trim (); - - FileService.CopyFile (Path.Combine (baseDir, filename), Path.Combine (targetDir, filename)); - monitor.Step ( 1 ); + using (var sw = new StringWriter ()) { + using (var chainedOutput = new LogTextWriter ()) { + chainedOutput.ChainWriter (monitor.Log); + chainedOutput.ChainWriter (sw); + + using (ProcessWrapper process = Runtime.ProcessService.StartProcess ("make", + "dist", + baseDir, + chainedOutput, + monitor.Log, + null)) { + process.WaitForOutput (); + + chainedOutput.UnchainWriter (monitor.Log); + chainedOutput.UnchainWriter (sw); + + if ( process.ExitCode > 0 ) + throw new Exception ( GettextCatalog.GetString ("An unspecified error occurred while running '{0}'", "make dist") ); + } + + monitor.Step ( 1 ); + + // FIXME: hackish way to get the created tarball's filename + string output = sw.ToString(); + int targz = output.LastIndexOf ( "tar.gz" ); + int begin = output.LastIndexOf ( '>', targz ); + + string filename = output.Substring ( begin + 1, (targz - begin) + 5 ).Trim (); + + FileService.CopyFile (Path.Combine (baseDir, filename), Path.Combine (targetDir, filename)); + monitor.Step ( 1 ); + } + } } catch ( Exception e ) { |