Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible Unreleased lock #2634

Closed
SoftQ opened this issue Jul 21, 2023 · 1 comment
Closed

Fix possible Unreleased lock #2634

SoftQ opened this issue Jul 21, 2023 · 1 comment
Assignees
Labels
Milestone

Comments

@SoftQ
Copy link
Contributor

SoftQ commented Jul 21, 2023

Tracking issue reported in https://github.com/SCADA-LTS/Scada-LTS/security/code-scanning/2166

@SoftQ SoftQ added the refactor label Jul 21, 2023
@SoftQ SoftQ added this to the 2.7.5.4 milestone Jul 21, 2023
@Limraj
Copy link
Collaborator

Limraj commented Jul 21, 2023

There is an unlock in the code in block finally :

    public boolean cancel() {
        synchronized (lock) {
            boolean result = (state == SCHEDULED);

            if (completeBeforeCancel) {
                try {
                    cancelLock.writeLock().lock();
                    state = CANCELLED;
                }
                finally {
                    cancelLock.writeLock().unlock();
                }
            }
            else
                state = CANCELLED;

            return result;
        }
    }

cancelLock.writeLock().unlock();

The only thing that could be slightly improved here is to throw lock() out of try:
https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/util/concurrent/locks/ReentrantReadWriteLock.html

Limraj added a commit that referenced this issue Aug 7, 2023
…ased_lock

#2634 Fix possible Unreleased lock - Lock outside the try block
@Limraj Limraj closed this as completed Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants