[Python] Fix double free of objects added to TH1::fFunctions#22493
Merged
LukasBreitwieser merged 3 commits intoJun 9, 2026
Conversation
Fixes root-project#22417 Provide the correct signal to the python bindings that calling `th1->GetListOfFunctions()->Add(object)` will take ownership of the object. ROOT's Python bindings use TCollection::IsOwner to decide whether objects inserted into a collection (like `TH1::fFunctions`) should be deleted (see `_TCollection_Add` pythonization). To ensure the Python bindings get the correct ownership signal, set the ownership on TH1::fFunctions. Although, in reality, TH1's destructor actually handles ownership, this solution still works, sinde the destructor removes all entries before deleting the collection.
vepadulano
reviewed
Jun 5, 2026
Test Results 22 files 22 suites 3d 21h 12m 41s ⏱️ Results for commit 07b91f0. ♻️ This comment has been updated with latest results. |
vepadulano
approved these changes
Jun 8, 2026
vepadulano
left a comment
Member
There was a problem hiding this comment.
I have re-checked the source code and I agree this should be the right approach without change of existing functionality. Thanks!
Contributor
Author
|
Thank you for your review @vepadulano! |
Member
|
/backport to 6.40 |
|
Preparing to backport PR #22493 to branch 6.40 requested by dpiparo |
|
This PR has been backported to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Provide the correct signal to the python bindings that calling
th1->GetListOfFunctions()->Add(object)will take ownership of the object.ROOT's Python bindings use TCollection::IsOwner to decide whether objects inserted into a collection (like
TH1::fFunctions) should be deleted (see_TCollection_Addpythonization). To ensure the Python bindings get the correct ownership signal, set the ownership on TH1::fFunctions. Although, in reality, TH1's destructor actually handles ownership, this solution still works, sinde the destructor removes all entries before deleting the collection.This PR fixes #22417.