I'm trying to implement a plugin that connects to a RTI for data encode / decode. Unfortunately I am running into some heap problems and I have no leads as to what might be causing them.
Here is the error I receive:
Critical error detected c0000374
Unhandled exception at 0x00007FFB6AF59059 (ntdll.dll) in FederatePublisher.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FFB6AFC27F0).
Here is the code that seems to trigger it:
wstring childDataType = basicType->getName();
...
else if (childDataType.compare(L"RPRunsignedInteger16") == 0)
{
for (char* ptr = (char*)data; ptr < (char*)data + sizeof(__int16); ptr++)
{
buffer.push_back(*ptr); //HERE IT IS TRIGGERED
}
return;
}
This code runs inside a method called encodeAttribute with the following signature:
void encodeAttribute(BasicDataType* basicType, void* data, vector<Octet>& buffer)
where Octet underlining type is char. the purpose of this code is to encode a value of unknown datatype (void* data) based on its name, thus correctly identifying its size, and then pushing as many bytes of the data inside a buffer, as its size requires. It breaks after running the loop for the second time (thus after doing push_back of the second byte), and here is the snippet where it ACTUALLY breaks:
_CRT_SECURITYCRITICAL_ATTRIBUTE
void __CRTDECL operator delete(void* const block) noexcept
{
#ifdef _DEBUG
_free_dbg(block, _UNKNOWN_BLOCK);
#else
free(block);
#endif //HERE IT BREAKS
}
This error is completely random, more often than not it happens at the beginning of the program run, but not always in the same spot, and sometimes it runs smoothly until I stop the test program manually. I test it by feeding it an entire class complete with attributes, it shouldn't matter that they are uninintialized as even random values should be correctly encoded.
Here is the call stack I get:
ntdll.dll!RtlReportCriticalFailure() Unknown
ntdll.dll!RtlpHeapHandleError() Unknown
ntdll.dll!RtlpHpHeapHandleError() Unknown
ntdll.dll!RtlpLogHeapFailure() Unknown
ntdll.dll!RtlpFreeHeapInternal() Unknown
ntdll.dll!RtlFreeHeap() Unknown
ucrtbased.dll!_free_base(void * block) Line 105 C++
ucrtbased.dll!free_dbg_nolock(void * const block, const int block_use) Line 1003 C++
ucrtbased.dll!_free_dbg(void * block, int block_use) Line 1030 C++
FederatePublisher.exe!operator delete(void * block) Line 38 C++
FederatePublisher.exe!operator delete(void * block, unsigned __int64 __formal) Line 32 C++
FederatePublisher.exe!std::vector<char,std::allocator<char>>::_Change_array(char * const _Newvec, const unsigned __int64 _Newsize, const unsigned __int64 _Newcapacity) Line 1904 C++
FederatePublisher.exe!std::vector<char,std::allocator<char>>::_Emplace_reallocate<char const &>(char * const _Whereptr, const char & <_Val_0>) Line 981 C++
FederatePublisher.exe!std::vector<char,std::allocator<char>>::emplace_back<char const &>(const char & <_Val_0>) Line 922 C++
FederatePublisher.exe!MakAgent::encodeAttribute(ObjectClassInstance * obj, BasicDataType * basicType, void * data, std::vector<char,std::allocator<char>> & buffer) Line 1268 C++
FederatePublisher.exe!MakAgent::encodeAndUpdateAttributes() Line 1084 C++
FederatePublisher.exe!Mak::PostExec() Line 86 C++
FederatePublisher.exe!main() Line 30 C++
User contributions licensed under CC BY-SA 3.0