Explorar el Código

file(LOCK): Close file descriptor/handle when releasing a lock

The file lock functionality added in commit v3.2.0-rc1~297^2~1 (file:
Add LOCK subcommand to do file and directory locking, 2014-11-26) forgot
to close the lock file descriptors.  Eventually it was possible to run
out of file descriptors and locks could not longer be acquired.  Fix
this by closing the file descriptor or handle when we are done with it.
Also set the member back to the initial value from the constructor
to leave everything in a consistent state (useful for debugging).

Co-Author: Ruslan Baratov <[email protected]>
Betsy McPhail hace 10 años
padre
commit
1f289095f9
Se han modificado 2 ficheros con 7 adiciones y 0 borrados
  1. 4 0
      Source/cmFileLockUnix.cxx
  2. 3 0
      Source/cmFileLockWin32.cxx

+ 4 - 0
Source/cmFileLockUnix.cxx

@@ -15,6 +15,7 @@
 #include <errno.h> // errno
 #include <errno.h> // errno
 #include <stdio.h> // SEEK_SET
 #include <stdio.h> // SEEK_SET
 #include <fcntl.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 
 
 cmFileLock::cmFileLock(): File(-1)
 cmFileLock::cmFileLock(): File(-1)
@@ -31,6 +32,9 @@ cmFileLockResult cmFileLock::Release()
 
 
   this->Filename = "";
   this->Filename = "";
 
 
+  ::close(this->File);
+  this->File = -1;
+
   if (lockResult == 0)
   if (lockResult == 0)
     {
     {
     return cmFileLockResult::MakeOk();
     return cmFileLockResult::MakeOk();

+ 3 - 0
Source/cmFileLockWin32.cxx

@@ -38,6 +38,9 @@ cmFileLockResult cmFileLock::Release()
 
 
   this->Filename = "";
   this->Filename = "";
 
 
+  CloseHandle(this->File);
+  this->File = INVALID_HANDLE_VALUE;
+
   if (unlockResult)
   if (unlockResult)
     {
     {
     return cmFileLockResult::MakeOk();
     return cmFileLockResult::MakeOk();