diff options
author | svidyuk <svidyuk@yandex-team.com> | 2022-11-21 14:40:11 +0300 |
---|---|---|
committer | svidyuk <svidyuk@yandex-team.com> | 2022-11-21 14:40:11 +0300 |
commit | b1c69808cc78d58df27cc15e729624bdeca42071 (patch) | |
tree | 42ef92bab3c830d6bd674b1480fd206f2f69ae26 /library/cpp | |
parent | d8296c2cef1913f2580fefe89ef24ec4c84f5c6c (diff) | |
download | ydb-b1c69808cc78d58df27cc15e729624bdeca42071.tar.gz |
Fix ya-bin crashes on win when yt-store is enabled
yt-store is enabled by default on all platforms including windows
PR:2997752 https://a.yandex-team.ru/review/2997752
adds ifdedfs for windows to enforce MSDN requirement that
memory allocated with _alligned_allocate must be deallocated with
_aligned_free.
PR:3110888 https://a.yandex-team.ru/review/3110888
removes 2 of 3 ifdefs added and introduces inconsistency
between allc/free functions on windows. Types with alignment
requiremens less then std::max_allign_t are allocated with malloc
and freed with _alligned_free. ya-bin release with this commit
crashes on windows unless user explicitelly disable yt-store.
Restore ifdefs which were removed in PR:3110888 in order to fix
the problem.
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/yt/memory/new-inl.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/new-inl.h b/library/cpp/yt/memory/new-inl.h index 978fa01aeb7..282a2a2515d 100644 --- a/library/cpp/yt/memory/new-inl.h +++ b/library/cpp/yt/memory/new-inl.h @@ -175,11 +175,15 @@ Y_FORCE_INLINE TIntrusivePtr<T> SafeConstruct(void* ptr, As&&... args) template <size_t Size, size_t Alignment> void* AllocateConstSizeAligned() { +#ifdef _win_ + return ::aligned_malloc(Size, Alignment); +#else if (Alignment <= alignof(std::max_align_t)) { return ::malloc(Size); } else { return ::aligned_malloc(Size, Alignment); } +#endif } } // namespace NDetail @@ -219,11 +223,15 @@ Y_FORCE_INLINE TIntrusivePtr<T> NewWithExtraSpace( auto totalSize = NYT::NDetail::TConstructHelper<T>::Size + extraSpaceSize; void* ptr = nullptr; +#ifdef _win_ + ptr = ::aligned_malloc(totalSize, NYT::NDetail::TConstructHelper<T>::Alignment); +#else if (NYT::NDetail::TConstructHelper<T>::Alignment <= alignof(std::max_align_t)) { ptr = ::malloc(totalSize); } else { ptr = ::aligned_malloc(totalSize, NYT::NDetail::TConstructHelper<T>::Alignment); } +#endif return NYT::NDetail::SafeConstruct<T>(ptr, std::forward<As>(args)...); } |