[cmake-commits] hoffman committed cmWin32ProcessExecution.cxx 1.30 1.31

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Jul 24 15:55:05 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv11320

Modified Files:
	cmWin32ProcessExecution.cxx 
Log Message:
ENH: fix resource leak


Index: cmWin32ProcessExecution.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmWin32ProcessExecution.cxx,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- cmWin32ProcessExecution.cxx	2 Mar 2007 15:50:45 -0000	1.30
+++ cmWin32ProcessExecution.cxx	24 Jul 2007 19:55:03 -0000	1.31
@@ -142,14 +142,11 @@
   if (!CreatePipe(&newstdin,&write_stdin,&sa,0)) 
 //create stdin pipe 
     {
-    std::cerr << "CreatePipe" << std::endl;
     return false;
- 
     }
   if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) 
 //create stdout pipe 
     {
-    std::cerr << "CreatePipe" << std::endl;
     CloseHandle(newstdin);
     CloseHandle(write_stdin);
     return false;
@@ -637,7 +634,21 @@
                                 this->hChildStdoutWr,
                                 &hProcess, this->HideWindows,
                                 this->Output))
+      {
+      if(fd1 >= 0)
+        {
+        close(fd1);
+        }
+      if(fd2 >= 0)
+        {
+        close(fd2);
+        }
+      if(fd3 >= 0)
+        {
+        close(fd3);
+        }
       return 0;
+      }
     }
   else 
     {
@@ -649,7 +660,21 @@
                                 this->hChildStderrWr,
                                 &hProcess, this->HideWindows,
                                 this->Output))
+      {
+      if(fd1 >= 0)
+        {
+        close(fd1);
+        }
+      if(fd2 >= 0)
+        {
+        close(fd2);
+        }
+      if(fd3 >= 0)
+        {
+        close(fd3);
+        }
       return 0;
+      }
     }
 
   /*
@@ -672,17 +697,14 @@
   this->ProcessHandle = hProcess;
   if ( fd1 >= 0 )
     {
-    //  this->StdIn = f1;
     this->pStdIn = fd1;
     }
   if ( fd2 >= 0 )
     {
-    //  this->StdOut = f2;
     this->pStdOut = fd2;
     }
   if ( fd3 >= 0 )
     {
-    //  this->StdErr = f3;
     this->pStdErr = fd3;
     }
 
@@ -691,6 +713,22 @@
 
 bool cmWin32ProcessExecution::CloseHandles()
 {
+  if(this->pStdErr != -1 )
+    {
+    _close(this->pStdErr);
+    this->pStdErr = -1;
+    }
+  if(this->pStdIn != -1 )
+    {
+    _close(this->pStdIn);
+    this->pStdIn = -1;
+    }
+  if(this->pStdOut != -1 )
+    {
+    _close(this->pStdOut);
+    this->pStdOut = -1;
+    }
+
   bool ret = true;
   if (this->hChildStdinRd && !CloseHandle(this->hChildStdinRd))
     {



More information about the Cmake-commits mailing list