From a6da439b47bd2d7c3772f4a94d199894d3edaee9 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 22 Feb 2023 02:42:32 +0100 Subject: [PATCH] Check if FileLock is valid before using or releasing it Change-Id: I23ba67b61b9b03772f33a929c080c0d02b8c8652 --- .../src/org/eclipse/jgit/internal/storage/file/GC.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 3f281a5d6..04c8418f6 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 @@ boolean lock() { 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 @@ private String getHostName() { public void close() { boolean wasLocked = false; try { - if (lock != null) { + if (lock != null && lock.isValid()) { lock.release(); wasLocked = true; }