From c29a4101164be8c8ff5c8cefdb1f29d66fe42bc0 Mon Sep 17 00:00:00 2001 From: Charles Schlosser Date: Fri, 12 Jan 2024 06:09:46 +0000 Subject: [PATCH] check pointers before freeing --- Eigen/src/Core/util/Memory.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 31f1057ee..62534540c 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -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(*(static_cast(ptr) - 1)); void* original = static_cast(static_cast(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(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