mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-15 23:20:05 +02:00
Fix deallocate for working on old compiers (#1478)
Co-authored-by: Jordan Bayles <bayles.jordan@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#ifndef JSON_ALLOCATOR_H_INCLUDED
|
||||
#define JSON_ALLOCATOR_H_INCLUDED
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
@@ -38,8 +39,16 @@ public:
|
||||
* The memory block is filled with zeroes before being released.
|
||||
*/
|
||||
void deallocate(pointer p, size_type n) {
|
||||
// memset_s is used because memset may be optimized away by the compiler
|
||||
// These constructs will not be removed by the compiler during optimization,
|
||||
// unlike memset.
|
||||
#if defined(HAVE_MEMSET_S)
|
||||
memset_s(p, n * sizeof(T), 0, n * sizeof(T));
|
||||
#elif defined(_WIN32)
|
||||
RtlSecureZeroMemory(p, n * sizeof(T));
|
||||
#else
|
||||
std::fill_n(reinterpret_cast<volatile unsigned char*>(p), n, 0);
|
||||
#endif
|
||||
|
||||
// free using "global operator delete"
|
||||
::operator delete(p);
|
||||
}
|
||||
|
Reference in New Issue
Block a user