Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch fixes the memory leak in zzX
When we are testing NTL::zz_pXModulus&getPhimXMod functions, if an exception occurs during the execution of the moduli.insert operation, it will result in the allocated memory not being released. Therefore, this modification uses smart pointers to avoid memory leaks
==47958==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 176 byte(s) in 1 object(s) allocated from:
#0 0x794a300b61e7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
#1 0x5777885d6c36 in helib::getPhimXMod(helib::PAlgebra const&) /home/uos/HElib-2.3.0/HElib-2.3.0/src/zzX.cpp:96
Indirect leak of 49152 byte(s) in 2 object(s) allocated from:
#0 0x794a300b6357 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:102
#1 0x794a2fda81c1 in long* NTL::MakeRawArray(long) ../include/NTL/SmartPtr.h:998
#2 0x794a2fda81c1 in NTL::UniqueArray::SetLength(long) ../include/NTL/SmartPtr.h:1620
#3 0x794a2fda81c1 in NTL::fftRep::DoSetSize(long, long) /home/uos/HElib-2.3.0/HElib-2.3.0/build/dependencies/Source/ntl_fetched/src/lzz_pX.cpp:1378
Indirect leak of 13888 byte(s) in 1 object(s) allocated from:
#0 0x794a300b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x577788032e4b in NTL::VecNTL::zz_p::AllocateTo(long) /home/uos/HElib-2.3.0/HElib-2.3.0/build/helib_pack/include/NTL/vector.h:653
Indirect leak of 56 byte(s) in 1 object(s) allocated from:
#0 0x794a300b64c7 in operator new(unsigned long, std::nothrow_t const&) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:105
#1 0x794a2fdac3a4 in NTL::Lazy<NTL::VecNTL::zz_p, NTL::DefaultDeleterPolicy>* NTL::MakeRaw<NTL::Lazy<NTL::VecNTL::zz_p, NTL::DefaultDeleterPolicy>>() ../include/NTL/SmartPtr.h:710
#2 0x794a2fdac3a4 in void NTL::UniquePtr<NTL::Lazy<NTL::VecNTL::zz_p, NTL::DefaultDeleterPolicy>, NTL::DefaultDeleterPolicy>::make<>() ../include/NTL/SmartPtr.h:1109
#3 0x794a2fdac3a4 in void NTL::OptionalVal<NTL::Lazy<NTL::VecNTL::zz_p, NTL::DefaultDeleterPolicy> >::make<>() ../include/NTL/SmartPtr.h:1479
#4 0x794a2fdac3a4 in NTL::build(NTL::zz_pXModulus&, NTL::zz_pX const&) /home/uos/HElib-2.3.0/HElib-2.3.0/build/dependencies/Source/ntl_fetched/src/lzz_pX.cpp:2845
SUMMARY: AddressSanitizer: 63272 byte(s) leaked in 5 allocation(s).