Skip to content

stored: fix race condition#2359

Merged
BareosBot merged 4 commits intobareos:masterfrom
sebsura:dev/master/ssura/fix-stored-crash
Sep 8, 2025
Merged

stored: fix race condition#2359
BareosBot merged 4 commits intobareos:masterfrom
sebsura:dev/master/ssura/fix-stored-crash

Conversation

@sebsura
Copy link
Contributor

@sebsura sebsura commented Sep 3, 2025

Because the decrement does not happen inside the lock, multiple threads can run into the "else" branch, which then causes a double free.

The better solution would be for decrement to return the value after the decrement, but as this is not performance cricital, the easy fix is probably the better one

fixes issue #2339.

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

Make sure you check/merge the PR using devtools/pr-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Required backport PRs have been created
  • Correct milestone is set
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

@sebsura sebsura requested a review from arogge September 3, 2025 09:49
@sebsura sebsura self-assigned this Sep 3, 2025
@sebsura sebsura added bugfix bug This addresses a bug labels Sep 3, 2025
@sebsura sebsura added this to the 25.0.0 milestone Sep 3, 2025
Copy link
Member

@pstorz pstorz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment

Because the decrement does not happen inside the lock, multiple
threads can run into the "else" branch, which then causes a double
free.

The better solution would be for decrement to return the value after
the decrement, but as this is not performance cricital, the easy fix
is probably the better one
Because of the way this list is implemented, we need to make sure that
we
1) never free an element still on the list, and
2) only remove elements that are _actually_ on the list.

So to make it safe to free the element in this function, we first
search for it in the list, and remove it if its on there.
@sebsura sebsura force-pushed the dev/master/ssura/fix-stored-crash branch from 11dbc4d to 870a315 Compare September 8, 2025 05:07
@BareosBot BareosBot merged commit 0207f7a into bareos:master Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants