Skip to content

Conversation

@ferdymercury
Copy link
Collaborator

This Pull request:

Changes or fixes:

Fixes #18322

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

@github-actions
Copy link

github-actions bot commented Apr 9, 2025

Test Results

    18 files      18 suites   4d 16h 27m 49s ⏱️
 2 722 tests  2 722 ✅ 0 💤 0 ❌
47 305 runs  47 305 ✅ 0 💤 0 ❌

Results for commit c4cace9.

@dpiparo
Copy link
Member

dpiparo commented Apr 9, 2025

Can we merge?

@guitargeek
Copy link
Contributor

What is _hashAssistedFind is a nullptr? Then this code branch will activate, and calling delete on a nullptr is not alllowed. Also, it would be better to set the pointer to nullptr after the delete, so there won't be a problem with dereferencing garbage pointers later

@ferdymercury
Copy link
Collaborator Author

ferdymercury commented Apr 10, 2025

What is _hashAssistedFind is a nullptr? Then this code branch will activate, and calling delete on a nullptr is not alllowed. Also, it would be better to set the pointer to nullptr after the delete, so there won't be a problem with dereferencing garbage pointers later

Delete on nullptr is okish, right?
According to cppreference: If ptr is a null pointer value, no destructors are called, and the deallocation function may or may not be called (it's unspecified), but the default deallocation functions are guaranteed to do nothing when passed a null pointer.

No need to set it to null after delete, right?
New is being called just below. In line 933.

Anyway I will change the first part as suggested, does not harm either.

@silverweed
Copy link
Contributor

Indeed, calling delete on a nullptr is perfectly valid and harmless, so the check is superfluous.
I'll ask here as well if we should take the occasion to change that variable to a unique_ptr though...

@guitargeek
Copy link
Contributor

Hi thanks @silverweed, I didn't know that! Sorry Ferdy for the confusion.

Unfortunately we can't migrate to std::unique_ptr until this PR is merged:

Copy link
Contributor

@guitargeek guitargeek left a comment

Choose a reason for hiding this comment

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

Thanks you very much for this PR! Sorry for making meaningless comments earlier, I really didn't know calling delete on a nullptr is okay :)

@guitargeek guitargeek merged commit 5616583 into root-project:master Apr 10, 2025
21 of 22 checks passed
@ferdymercury ferdymercury deleted the findhash2 branch April 10, 2025 06:55
guitargeek pushed a commit that referenced this pull request Apr 11, 2025
Fixes memory leaks found by valgrind. Similar to #18327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RF] "Definitely lost" reported by Valgrind in RooAbsCollection

5 participants