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

Memory Error---test_params2 #2867

Closed
shaomeng opened this issue Sep 30, 2021 · 4 comments · Fixed by #2879
Closed

Memory Error---test_params2 #2867

shaomeng opened this issue Sep 30, 2021 · 4 comments · Fixed by #2879
Assignees
Milestone

Comments

@shaomeng
Copy link
Collaborator

Utility program test_params2 has definitely lost memory errors:

==151381== LEAK SUMMARY:
==151381==    definitely lost: 104 bytes in 1 blocks
==151381==    indirectly lost: 56 bytes in 1 blocks
==151381==      possibly lost: 0 bytes in 0 blocks
==151381==    still reachable: 4,096 bytes in 1 blocks
==151381==         suppressed: 0 bytes in 0 blocks
==151381== Rerun with --leak-check=full to see details of leaked memory
@shaomeng shaomeng added the Bug label Sep 30, 2021
@sgpearse sgpearse added the High label Oct 5, 2021
shaomeng pushed a commit that referenced this issue Oct 26, 2021
@shaomeng shaomeng mentioned this issue Oct 26, 2021
shaomeng added a commit that referenced this issue Nov 9, 2021
* fix #2871

* move test binaries to their own directory

* fix #2867

* sync

* minor

Co-authored-by: Samuel Li <shaomeng@cisl-vapor>
@sgpearse sgpearse added this to the 3_6_0 Release milestone Jan 24, 2022
@clyne
Copy link
Collaborator

clyne commented Jan 31, 2022

The leaks are fixed, but there is still a memory error:

perator()(VAPoR::ParamsContainer*) const (memory:2084)
==63237== by 0x1001E476B: std::__1::unique_ptr<VAPoR::ParamsContainer, std::__1::default_deleteVAPoR::ParamsContainer >::reset(VAPoR::ParamsContainer*) (memory:2345)
==63237== by 0x1001E7E48: std::__1::unique_ptr<VAPoR::ParamsContainer, std::__1::default_deleteVAPoR::ParamsContainer >::~unique_ptr() (memory:2299)
==63237== by 0x1001E47B4: std::__1::unique_ptr<VAPoR::ParamsContainer, std::__1::default_deleteVAPoR::ParamsContainer >::~unique_ptr() (memory:2299)
==63237== by 0x1001E4EB6: VAPoR::ViewpointParams::~ViewpointParams() (lib/params/ViewpointParams.cpp:127)

==63237== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

@clyne clyne reopened this Jan 31, 2022
@shaomeng
Copy link
Collaborator Author

shaomeng commented Feb 2, 2022

@clyne The current memory error is because of an XmlNode being free'd and then it's accessed again.

The memory management with regard to XmlNodes and how Params make use of them seem quite complicated though, and I cannot see an easy fix to this particular error without completely revamping the XmlNode/Params code with smart pointers. Then the question becomes, do we go down that path now?

@clyne
Copy link
Collaborator

clyne commented Feb 2, 2022

@shaomeng this problem looks like a regression that was introduced by your commit to ViewpointParams.cpp, which introduced smart pointers (d1063b1). It's not clear to me that smart pointers and raw pointers can be mixed in this way, but I really don't know. Perhaps the above commit should be backed out?

@shaomeng
Copy link
Collaborator Author

shaomeng commented Feb 2, 2022

@clyne Yeah, that commit used a unique pointer to wrap around an instance of ParamsContainer, so that instance of ParamsContainer would later be properly destroyed. As a result, Valgrind doesn't report a "Definitely Lost" memory block anymore, and the original bug was fixed. If that commit was backed out, the ParamsContainer instance would be lost.

It seems to me that when an instance of ParamsContainer was destroyed, it destroyed some XmlNodes it owns all together, but that XmlNode was accessed by some other code, causing the illegal access bug you reported. However, the complexity of XmlNode/ParamsBase code and very frequent use of pointer assignments prevented me from pinpointing where exactly that bug is.

I don't think there's mixed use of smart and raw pointer. There's one particular pointer, named _transforms, that's managed by a smart pointer. The smart pointer manages the lifespan of variable _transforms and that's it.

clyne added a commit that referenced this issue Feb 2, 2022
@clyne clyne closed this as completed in 9031812 Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants