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

[RF] Fix memory leaks in RooFitHS3 by completely avoiding manual memory management #9690

Merged
merged 2 commits into from
Jan 26, 2022

Conversation

guitargeek
Copy link
Contributor

@guitargeek guitargeek commented Jan 25, 2022

This PR fixes tons of memory leaks in RooFitHS3 by never using manual memory allocation in RooFitHS3.

To facilitate this, an overload of RooAbsArg::addOwnedComponents was added that takes transfers the ownership via smart pointers (otherwise one would have to use raw owning pointers or std::unique_ptr<T>::release() which I want to avoid).

If the CI passes, I'll squash the second and third commit and add commit messages.

@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link

Build failed on mac1015/python3.
Running on macitois21.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2022-01-25T14:48:14.148Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/roofit/hs3/src/RooJSONFactoryWSTool.cxx:297:49: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
  • [2022-01-25T14:48:14.148Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/roofit/hs3/src/RooJSONFactoryWSTool.cxx:305:60: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]

@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

@guitargeek guitargeek marked this pull request as ready for review January 25, 2022 18:04
@guitargeek guitargeek changed the title Use smart pointers in RooFitHS3 [RF] Fix various memory leaks in RooFitHS3 my completely avoiding manual memory management Jan 25, 2022
@guitargeek
Copy link
Contributor Author

@cburgard and @gartrog, if you want to take a look

@guitargeek guitargeek changed the title [RF] Fix various memory leaks in RooFitHS3 my completely avoiding manual memory management [RF] Fix memory leaks in RooFitHS3 by completely avoiding manual memory management Jan 25, 2022
The usecase for this overload is to transfer the ownership of RooAbsArgs
from `std::unique_ptr` to another RooAbsArg, without having to call
`release()` on the smart pointer, which is a code smell because
ownership should always be clear without the smart pointer having to
release it.
Calling `new` and `delete` is now completely avoided in RooFitHS3, and
`std::unique_ptr` is always used instead.
@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1015/python3, mac11/cxx17, windows10/cxx14
How to customize builds

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

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

LGTM!
Thank you for the fix !

@guitargeek guitargeek merged commit 783a5c7 into root-project:master Jan 26, 2022
@guitargeek guitargeek deleted the hs3_memory_leaks branch January 26, 2022 08:53
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