changeset 4013:54d9513f87a4

7032589: FileHandler leaking file descriptor of the file lock Reviewed-by: forax, dcubed
author mchung
date Fri, 15 Apr 2011 23:42:12 -0700
parents 131ed7967996
children 007b2535a7f5
files src/share/classes/java/util/logging/FileHandler.java
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/logging/FileHandler.java	Fri Apr 15 15:56:12 2011 -0700
+++ b/src/share/classes/java/util/logging/FileHandler.java	Fri Apr 15 23:42:12 2011 -0700
@@ -409,22 +409,25 @@
                     // Try the next file.
                     continue;
                 }
+                boolean available;
                 try {
-                    FileLock fl = fc.tryLock();
-                    if (fl == null) {
-                        // We failed to get the lock.  Try next file.
-                        continue;
-                    }
+                    available = fc.tryLock() != null;
                     // We got the lock OK.
                 } catch (IOException ix) {
                     // We got an IOException while trying to get the lock.
                     // This normally indicates that locking is not supported
                     // on the target directory.  We have to proceed without
                     // getting a lock.   Drop through.
+                    available = true;
                 }
-                // We got the lock.  Remember it.
-                locks.put(lockFileName, lockFileName);
-                break;
+                if (available) {
+                    // We got the lock.  Remember it.
+                    locks.put(lockFileName, lockFileName);
+                    break;
+                }
+
+                // We failed to get the lock.  Try next file.
+                fc.close();
             }
         }