check pointers before freeing

This commit is contained in:
Charles Schlosser 2024-01-12 06:09:46 +00:00 committed by Antonio Sánchez
parent 48e0c827da
commit c29a410116

View File

@ -156,7 +156,7 @@ EIGEN_DEVICE_FUNC inline void* handmade_aligned_malloc(std::size_t size,
/** \internal Frees memory allocated with handmade_aligned_malloc */
EIGEN_DEVICE_FUNC inline void handmade_aligned_free(void* ptr) {
if (ptr) {
if (ptr != nullptr) {
uint8_t offset = static_cast<uint8_t>(*(static_cast<uint8_t*>(ptr) - 1));
void* original = static_cast<void*>(static_cast<uint8_t*>(ptr) - offset);
@ -224,9 +224,11 @@ EIGEN_DEVICE_FUNC inline void* aligned_malloc(std::size_t size) {
EIGEN_DEVICE_FUNC inline void aligned_free(void* ptr) {
#if (EIGEN_DEFAULT_ALIGN_BYTES == 0) || EIGEN_MALLOC_ALREADY_ALIGNED
if (ptr) check_that_malloc_is_allowed();
EIGEN_USING_STD(free)
free(ptr);
if (ptr != nullptr) {
check_that_malloc_is_allowed();
EIGEN_USING_STD(free)
free(ptr);
}
#else
handmade_aligned_free(ptr);
@ -294,9 +296,11 @@ EIGEN_DEVICE_FUNC inline void conditional_aligned_free(void* ptr) {
template <>
EIGEN_DEVICE_FUNC inline void conditional_aligned_free<false>(void* ptr) {
if (ptr) check_that_malloc_is_allowed();
EIGEN_USING_STD(free)
free(ptr);
if (ptr != nullptr) {
check_that_malloc_is_allowed();
EIGEN_USING_STD(free)
free(ptr);
}
}
template <bool Align>