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 various memory leaks #1723

Merged
merged 16 commits into from
May 29, 2024

Conversation

sebsura
Copy link
Contributor

@sebsura sebsura commented Mar 1, 2024

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
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
Tests
  • Decision taken that a test is required (if not, then remove this paragraph)
  • The choice of the type of test (unit test or systemtest) is reasonable
  • Testname matches exactly what is being tested
  • On a fail, output of the test leads quickly to the origin of the fault

@sebsura sebsura force-pushed the dev/ssura/master/fix-various-leaks branch 2 times, most recently from 92d1d7d to 2145733 Compare March 20, 2024 10:47
@arogge arogge added the bugfix label Apr 2, 2024
@arogge arogge added this to the 24.0.0 milestone Apr 2, 2024
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

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

That is a huge improvement! How did you find all of these?
I have a few remarks. Nothing critical though.

core/src/cats/postgresql.cc Outdated Show resolved Hide resolved
core/src/dird/dbcheck_utils.cc Outdated Show resolved Hide resolved
core/src/dird/dbcheck_utils.h Outdated Show resolved Hide resolved
core/src/stored/acquire.cc Outdated Show resolved Hide resolved
core/src/stored/acquire.cc Outdated Show resolved Hide resolved
core/src/stored/acquire.cc Outdated Show resolved Hide resolved
@sebsura
Copy link
Contributor Author

sebsura commented May 23, 2024

I gathered all the logs created by asan with our test suite.

@sebsura sebsura requested a review from arogge May 24, 2024 05:00
@sebsura sebsura force-pushed the dev/ssura/master/fix-various-leaks branch from b780ff7 to 1ae4aea Compare May 24, 2024 05:01
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

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

The code looks great.
However, the new dbcheck test fails everywhere, so you'll have to take another look.

@arogge
Copy link
Member

arogge commented May 24, 2024

Do you think we should backport some/all of these into 23?

@sebsura
Copy link
Contributor Author

sebsura commented May 27, 2024

Ill try to backport it and ill see what works.

@sebsura sebsura mentioned this pull request May 27, 2024
6 tasks
@sebsura sebsura force-pushed the dev/ssura/master/fix-various-leaks branch 2 times, most recently from 30eea5b to d220b39 Compare May 29, 2024 13:15
sebsura added 13 commits May 29, 2024 17:23
PQfinish _always_ has to be called on db_handle_, if its not null:

https://www.postgresql.org/docs/current/libpq-connect.html

"Note that when PQconnectStart or PQconnectStartParams returns a
non-null pointer, you must call PQfinish when you are finished with
it, in order to dispose of the structure and any associated memory
blocks.  This must be done even if the connection attempt fails or is
abandoned."

PQexec() always allocates a new result object, that always has to be
freed with PQclear()!
Instead of hunting down every place where this could get leaked, we
instead use PoolMem to do so automatically.
Removing unecessary code since stifle_history() already ensures that
we only have at most history_max_entries inside our history.
Regardless this is a leak because remove_history returns to us a
HIST_ENTRY* that we are supposed to free on our own (which we do not
do!).
When an error occurs during the resource scanning, then the scanned
resource is not added to any list, which means its memory is never
freed.  As such we free the allocated resource here but calling the
appropriate callback.
@BareosBot BareosBot force-pushed the dev/ssura/master/fix-various-leaks branch from e44b4e7 to 318258a Compare May 29, 2024 17:23
@BareosBot BareosBot merged commit ba928ee into bareos:master May 29, 2024
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.

None yet

3 participants