mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-06 19:10:36 +08:00
check pointers before freeing
This commit is contained in:
parent
48e0c827da
commit
c29a410116
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user