mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +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 */
|
/** \internal Frees memory allocated with handmade_aligned_malloc */
|
||||||
EIGEN_DEVICE_FUNC inline void handmade_aligned_free(void* ptr) {
|
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));
|
uint8_t offset = static_cast<uint8_t>(*(static_cast<uint8_t*>(ptr) - 1));
|
||||||
void* original = static_cast<void*>(static_cast<uint8_t*>(ptr) - offset);
|
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) {
|
EIGEN_DEVICE_FUNC inline void aligned_free(void* ptr) {
|
||||||
#if (EIGEN_DEFAULT_ALIGN_BYTES == 0) || EIGEN_MALLOC_ALREADY_ALIGNED
|
#if (EIGEN_DEFAULT_ALIGN_BYTES == 0) || EIGEN_MALLOC_ALREADY_ALIGNED
|
||||||
|
|
||||||
if (ptr) check_that_malloc_is_allowed();
|
if (ptr != nullptr) {
|
||||||
|
check_that_malloc_is_allowed();
|
||||||
EIGEN_USING_STD(free)
|
EIGEN_USING_STD(free)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
handmade_aligned_free(ptr);
|
handmade_aligned_free(ptr);
|
||||||
@ -294,10 +296,12 @@ EIGEN_DEVICE_FUNC inline void conditional_aligned_free(void* ptr) {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
EIGEN_DEVICE_FUNC inline void conditional_aligned_free<false>(void* ptr) {
|
EIGEN_DEVICE_FUNC inline void conditional_aligned_free<false>(void* ptr) {
|
||||||
if (ptr) check_that_malloc_is_allowed();
|
if (ptr != nullptr) {
|
||||||
|
check_that_malloc_is_allowed();
|
||||||
EIGEN_USING_STD(free)
|
EIGEN_USING_STD(free)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <bool Align>
|
template <bool Align>
|
||||||
EIGEN_DEVICE_FUNC inline void* conditional_aligned_realloc(void* ptr, std::size_t new_size, std::size_t old_size) {
|
EIGEN_DEVICE_FUNC inline void* conditional_aligned_realloc(void* ptr, std::size_t new_size, std::size_t old_size) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user