| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 53cb9f3 commit 816e1be
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -609,9 +609,11 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { | |||
| 609 | 609 | return AllocForBrotli(data, real_size); | |
| 610 | 610 | } | |
| 611 | 611 | ||
| 612 | + static constexpr size_t reserveSizeAndAlign = | ||
| 613 | + std::max(sizeof(size_t), alignof(max_align_t)); | ||
| 614 | + | ||
| 612 | 615 | static void* AllocForBrotli(void* data, size_t size) { | |
| 613 | - constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t)); | ||
| 614 | - size += offset; | ||
| 616 | + size += reserveSizeAndAlign; | ||
| 615 | 617 | CompressionStream* ctx = static_cast<CompressionStream*>(data); | |
| 616 | 618 | char* memory = UncheckedMalloc(size); | |
| 617 | 619 | if (memory == nullptr) [[unlikely]] { | |
@@ -620,16 +622,15 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { | |||
| 620 | 622 | *reinterpret_cast<size_t*>(memory) = size; | |
| 621 | 623 | ctx->unreported_allocations_.fetch_add(size, | |
| 622 | 624 | std::memory_order_relaxed); | |
| 623 | - return memory + offset; | ||
| 625 | + return memory + reserveSizeAndAlign; | ||
| 624 | 626 | } | |
| 625 | 627 | ||
| 626 | 628 | static void FreeForZlib(void* data, void* pointer) { | |
| 627 | 629 | if (pointer == nullptr) [[unlikely]] { | |
| 628 | 630 | return; | |
| 629 | 631 | } | |
| 630 | 632 | CompressionStream* ctx = static_cast<CompressionStream*>(data); | |
| 631 | - constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t)); | ||
| 632 | - char* real_pointer = static_cast<char*>(pointer) - offset; | ||
| 633 | + char* real_pointer = static_cast<char*>(pointer) - reserveSizeAndAlign; | ||
| 633 | 634 | size_t real_size = *reinterpret_cast<size_t*>(real_pointer); | |
| 634 | 635 | ctx->unreported_allocations_.fetch_sub(real_size, | |
| 635 | 636 | std::memory_order_relaxed); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments