10BC0
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4aaa843 commit f2159f2Copy full SHA for f2159f2
src/node_zlib.cc
@@ -608,7 +608,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
608
}
609
610
static void* AllocForBrotli(void* data, size_t size) {
611
- size += sizeof(size_t);
+ constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
612
+ size += offset;
613
CompressionStream* ctx = static_cast<CompressionStream*>(data);
614
char* memory = UncheckedMalloc(size);
615
if (memory == nullptr) [[unlikely]] {
@@ -617,15 +618,16 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
617
618
*reinterpret_cast<size_t*>(memory) = size;
619
ctx->unreported_allocations_.fetch_add(size,
620
std::memory_order_relaxed);
- return memory + sizeof(size_t);
621
+ return memory + offset;
622
623
624
static void FreeForZlib(void* data, void* pointer) {
625
if (pointer == nullptr) [[unlikely]] {
626
return;
627
628
- char* real_pointer = static_cast<char*>(pointer) - sizeof(size_t);
629
630
+ char* real_pointer = static_cast<char*>(pointer) - offset;
631
size_t real_size = *reinterpret_cast<size_t*>(real_pointer);
632
ctx->unreported_allocations_.fetch_sub(real_size,
633