Fix Valgrind memory errors#1263
Conversation
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
Improve ComponentInfo move constructor Make getComponentInfoMap() const
83d5346 to
9441945
Compare
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
|
Status Flag 'Pre-Test Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED by label AT: PRE-TEST INSPECTED! Autotester is Removing Label; this inspection will remain valid until a new commit to source branch is performed. |
|
Status Flag 'Pull Request AutoTester' - Testing Jenkins Projects: Pull Request Auto Testing STARTING (click to expand)Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MR-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MT-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-macro_withsstcore
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-core_Make-Dist
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_Clang-Format_sst-core
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-14-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-14-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-macro_withsstcore
Using Repos:
Pull Request Author: leekillough |
|
Status Flag 'Pull Request AutoTester' - Jenkins Testing: all Jobs PASSED Pull Request Auto Testing has PASSED (click to expand)Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MR-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MT-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-macro_withsstcore
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-core_Make-Dist
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_Clang-Format_sst-core
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-14-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-14-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-macro_withsstcore
|
|
Status Flag 'Pre-Merge Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED AND APPROVED by [ feldergast ]! |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
4 similar comments
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
This fixes some Valgrind memory errors:
ConfigComponent,slot_numandstatLoadLevelwere not being initialized (maybe because they only apply in some cases -- aslot_numcomment says "Only valid for subcomponents") and whenConfigComponentis serialized, it causes Valgrind to report an uninitialized memory read. This change simply addsslot_num(0)andstatLoadLevel(0)to the constructors to initialize them to0and avoid uninitialized memory reads.SSTPythonModelDefinitionconstructor, anargvarray ismalloc()ed and then each of the argument pointers are separatelymalloc()ed. But then when it finishes, it onlyfree()s theargvarray, but not its individual arguments.pymodel_comp.cc,compInit()allocates a string by callinggModel->addNamePrefix(name)and then passes it as achar*togModel->addComponent(), which constructs astd::stringcopy of it by implicitly converting thechar*argument tostd::string. But then it is not freed. It would have been better ifaddNamePrefix()returned astd::stringwhich automatically gets destroyed, but it would be too much work to change and test changing this API, so the pointer returned byaddComponent()isfree()ed after it is converted to astd::stringin the call toaddComponent().CoreTestCheckPoint, random number generators are initialized withnewduring construction, but are notdeleted in the destructor. As a precaution, all pointers to allocated memory are default-initialized tonullptrbefore the constructor body begins, so that they can be passed todeleteeven if they never got initialized withnew(say, if an exception was thrown in the constructor). There is another memory leak inCoreTestCheckPoint::clock_handler, but because of how it is handled during checkpoint/restart, it is not as simple asdelete-ing it in the destructor, since it is re-initialized strangely during checkpoint/restart and theCoreTestCheckPointis not completely destroyed and re-constructed during checkpoint/restart phases, but it is left in a partial state and re-initialized. So this leak, which is reported as a "definite leak" by Valgrind, will require a better solution. Since thisCoreTestCheckPointdoes not appear to be a part of main Core but rather testing, and the leaks were found with Valgrind while runningsst-test-core, it is lower priority that these leaks be fixed.As a bonus, but not fixing any memory errors,
ComponentInfoalready had an explicitly-defined move constructor, but it did not usestd::move()on two of itsstd::stringandstd::vectormembers, sostd::move()was added so that thestd::stringandstd::vectorhave shallow moves instead of deep copies.Also
Simulation_impl::getComponentInfoMap(), which returns the Component Info Map, was markedconst, since it is best practice that getters should beconst.