Skip to content

Conversation

@mo-lormi
Copy link
Contributor

@mo-lormi mo-lormi commented Nov 5, 2024


Description


This PR is intended to fix a bug (memory leakage) in the I/O processing procedure part of the MONIO package

Recently, debugging/profiling of the application lfricjedi_hofx.x (OOPS class: oops::HofX4D) has been carried out by using the AddressSanitizer (ASan) tool.

During this investigation, a few memory leaks have been identified.
A subset of them are associated with the I/O processing procedure part of the MONIO package.

* debugging/profiling (before)

The output of the debugging/profiling can be found here.

* solution:

The memory leaks occurs because the resources allocated for the data structure dataFile_ are not correctly deallocated at the end.

The bug/issue is related with the call of the destructor of std::unique_ptr, in particular it is related with the difference between the two methods std::unique_ptr::release() and std::unique_ptr::reset().
For details see here, here, and here.

* debugging/profiling (after)

The output of the debugging/profiling carried out after fixing the bug can be found here.


Issue(s) addressed

issue #48


Acceptance Criteria (Definition of Done)

All the tests pass.


@mo-lormi mo-lormi self-assigned this Nov 5, 2024
@mo-lormi mo-lormi marked this pull request as ready for review November 5, 2024 10:13
@mo-lormi mo-lormi requested review from odlomax and phlndrwd November 5, 2024 10:13
@mo-lormi mo-lormi added the bug Something isn't working label Nov 5, 2024
Copy link
Contributor

@phlndrwd phlndrwd left a comment

Choose a reason for hiding this comment

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

Good spot, Lorenzo! There's me thinking that smart pointers prevented memory leaks. This wouldn't have happened with good old new and delete.

@mo-lormi
Copy link
Contributor Author

mo-lormi commented Nov 5, 2024

"This wouldn't have happened with good old new and delete ..."

Well, I don't know ... I am not sure about that.

P.S. -- C++ ... a such (very) easy, wonderful language ...

@phlndrwd
Copy link
Contributor

phlndrwd commented Nov 5, 2024

@odlomax I think that @mo-lormi's work here is an interesting commentary on the pitfalls of smart pointers. I understand we're using them because of the perception that they prevent memory leaks, but this story shows how they introduce another set of rules and procedures that need to be understood to prevent them.

"This wouldn't have happened with good old new and delete ..."

Well, I don't know ... I am not sure about that.

P.S. -- C++ ... a such (very) easy, wonderful language ...

If I were writing it. I learned new and delete first and felt very comfortable using them. I felt there was a purity and simplicity around needing to pair every new with a corresponding delete. Life was simple back then. When all this was fields. Haha!

Copy link
Contributor

@mo-joshuacolclough mo-joshuacolclough left a comment

Choose a reason for hiding this comment

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

Great find

@phlndrwd phlndrwd merged commit 169ebb7 into develop Nov 6, 2024
4 checks passed
@mo-lormi mo-lormi deleted the feature/fix_bug_memory_manag branch March 10, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants