Browse Source

* Prevent file handle leak

Michaël Van Canneyt 1 year ago
parent
commit
c3339e9a51
1 changed files with 6 additions and 3 deletions
  1. 6 3
      rtl/unix/sysutils.pp

+ 6 - 3
rtl/unix/sysutils.pp

@@ -514,9 +514,12 @@ begin
     (which we can by definition) }
   fd:=FileOpenNoLocking(FileName,ShareMode);
   { the file exists, check whether our locking request is compatible }
-  if (fd>=0) and ((ShareMode and fmShareNoLocking)=0) then
+  if (fd>=0) then
     begin
-      Result:=DoFileLocking(fd,ShareMode);
+      if ((ShareMode and fmShareNoLocking)=0) then
+        Result:=DoFileLocking(fd,ShareMode)
+      else
+        Result:=0;
       FileClose(fd);
      { Can't lock -> abort }
       if Result<0 then
@@ -524,7 +527,7 @@ begin
     end;
   { now create the file }
   Result:=FileCreate(FileName,Rights);
-  if (ShareMode and fmShareNoLocking)=0 then
+  if ((ShareMode and fmShareNoLocking)=0) then
     Result:=DoFileLocking(Result,ShareMode);
 end;