FairRoot icon indicating copy to clipboard operation
FairRoot copied to clipboard

fix: Handle Sink/Source ownership more properly

Open ChristianTackeGSI opened this issue 2 years ago • 2 comments

Waiting for:

  • [x] #1442

FairRootManager and FairRun both used to delete fSink and fSource. In specific situations (FairRootManager getting destructed before FairRun) this leads to a double delete!

Deprecate the old FairRootManager::Set{Source,Sink} APIs that take something like an owning pointer. Introduce new Set{Sink,Source}NonOwning internal APIs.

See: https://github.com/FairRootGroup/FairRoot/issues/1418 (see "Double deleting of file source in FairRootManager and FairRun")


Checklist:

ChristianTackeGSI avatar Jul 19 '23 21:07 ChristianTackeGSI

@YanzhaoW: This should fix the second part of #1418. Could you take a look?

ChristianTackeGSI avatar Jul 19 '23 21:07 ChristianTackeGSI

Walkthrough

Walkthrough

The recent updates to the FairRoot framework primarily focus on modernizing memory management and improving code maintainability. Key changes include transitioning from raw pointers to std::unique_ptr for resource management, updating copyright years, and refining the handling of source and sink objects. These modifications enhance memory safety and align with modern C++ best practices.

Changes

Files Change Summary
fairroot/base/steer/FairRootManager.cxx Updated copyright year, removed initialization and deletion of fSource and fSink, adjusted conditional check in GetNameFromFile.
fairroot/base/steer/FairRootManager.h Updated copyright year, replaced FairLogger with FairMemory, added friend class for FairRun, deprecated SetSource and SetSink, used maybe_owning_ptr.
fairroot/base/steer/FairRun.cxx Added using statements for fairroot::detail, modified handling of fSource and fSink with unique pointers, deprecated SetOutputFile and SetOutputFileName.

Recent Review Details

Configuration used: CodeRabbit UI Review profile: CHILL

Commits Files that changed from the base of the PR and between 87dd3b9c467aad9d0e99b4d5216e612929bc3e11 and 21930e161dc7021ec0c6b323224cb0dc20ebe578.
Files selected for processing (3)
  • fairroot/base/steer/FairRootManager.cxx (5 hunks)
  • fairroot/base/steer/FairRootManager.h (6 hunks)
  • fairroot/base/steer/FairRun.cxx (6 hunks)
Files not reviewed due to errors (1)
  • fairroot/base/steer/FairRun.cxx (no review received)
Additional comments not posted (5)
fairroot/base/steer/FairRootManager.h (4)

11-11: Updating the include from FairLogger.h to FairMemory.h is appropriate given the shift towards improved memory management in the class.


53-54: Adding FairRun as a friend class to FairRootManager allows FairRun to access private members of FairRootManager. This is necessary for the changes in ownership handling described in the PR.


224-224: The deprecation of SetSource and SetSink while transitioning to std::unique_ptr for fSource and fSink is a significant improvement in memory management. This change helps prevent issues like memory leaks and double deletions.

Also applies to: 228-228


380-380: The change to use maybe_owning_ptr for fSource and fSink in FairRootManager aligns with modern C++ practices and the overall goal of the PR to handle object ownership more effectively.

Also applies to: 387-387

fairroot/base/steer/FairRootManager.cxx (1)

385-385: Verify the logic in SpecifyRunId and ReadEvent.

The logic in SpecifyRunId and ReadEvent methods should be carefully reviewed to ensure that fSource is always valid when accessed. The current implementation checks for fSource being null, but it might be beneficial to ensure that all paths that lead to these accesses are safe.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 17 '24 07:04 coderabbitai[bot]