From: Matthias Sohn Date: Wed, 22 Feb 2023 01:42:32 +0000 (+0100) Subject: Check if FileLock is valid before using or releasing it X-Git-Tag: v6.5.0.202302221508-m3~1^2^2^2^2^2^2^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a6da439b47bd2d7c3772f4a94d199894d3edaee9;p=jgit.git Check if FileLock is valid before using or releasing it Change-Id: I23ba67b61b9b03772f33a929c080c0d02b8c8652 --- diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 3f281a5d6c..04c8418f6d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -1649,7 +1649,7 @@ public class GC { f = new RandomAccessFile(pidFile.toFile(), "rw"); //$NON-NLS-1$ channel = f.getChannel(); lock = channel.tryLock(); - if (lock == null) { + if (lock == null || !lock.isValid()) { failedToLock(); return false; } @@ -1738,7 +1738,7 @@ public class GC { public void close() { boolean wasLocked = false; try { - if (lock != null) { + if (lock != null && lock.isValid()) { lock.release(); wasLocked = true; }