mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
operator delete should check for null pointer before deallocating
It is a pervasive belief that using "delete" with a null pointer is safe, so our custom delete operators should also handle this case correctly. This may fix regressions introduced by #934
This commit is contained in:
parent
316d254c64
commit
9159fc1029
@ -1124,7 +1124,9 @@ operator new(size_t size) {
|
|||||||
*/
|
*/
|
||||||
INLINE void DCPacker::StackElement::
|
INLINE void DCPacker::StackElement::
|
||||||
operator delete(void *ptr) {
|
operator delete(void *ptr) {
|
||||||
|
if (ptr != nullptr) {
|
||||||
StackElement *obj = (StackElement *)ptr;
|
StackElement *obj = (StackElement *)ptr;
|
||||||
obj->_next = _deleted_chain;
|
obj->_next = _deleted_chain;
|
||||||
_deleted_chain = obj;
|
_deleted_chain = obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,10 @@ public:
|
|||||||
return ptr; \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
inline void operator delete(void *ptr) { \
|
inline void operator delete(void *ptr) { \
|
||||||
|
if (ptr != nullptr) { \
|
||||||
StaticDeletedChain< Type >::deallocate((Type *)ptr, get_type_handle(Type)); \
|
StaticDeletedChain< Type >::deallocate((Type *)ptr, get_type_handle(Type)); \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
inline void operator delete(void *, void *) { \
|
inline void operator delete(void *, void *) { \
|
||||||
} \
|
} \
|
||||||
inline static bool validate_ptr(const void *ptr) { \
|
inline static bool validate_ptr(const void *ptr) { \
|
||||||
@ -104,8 +106,10 @@ public:
|
|||||||
return ptr; \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
inline void operator delete(void *ptr) { \
|
inline void operator delete(void *ptr) { \
|
||||||
|
if (ptr != nullptr) { \
|
||||||
_deleted_chain.deallocate((Type *)ptr, get_type_handle(Type)); \
|
_deleted_chain.deallocate((Type *)ptr, get_type_handle(Type)); \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
inline void operator delete(void *, void *) { \
|
inline void operator delete(void *, void *) { \
|
||||||
} \
|
} \
|
||||||
inline static bool validate_ptr(const void *ptr) { \
|
inline static bool validate_ptr(const void *ptr) { \
|
||||||
|
@ -32,8 +32,10 @@
|
|||||||
return ptr; \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
inline void operator delete(void *ptr) { \
|
inline void operator delete(void *ptr) { \
|
||||||
|
if (ptr != nullptr) { \
|
||||||
PANDA_FREE_SINGLE(ptr); \
|
PANDA_FREE_SINGLE(ptr); \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
inline void operator delete(void *, void *) { \
|
inline void operator delete(void *, void *) { \
|
||||||
} \
|
} \
|
||||||
inline void *operator new[](size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT) { \
|
inline void *operator new[](size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT) { \
|
||||||
@ -44,8 +46,10 @@
|
|||||||
return ptr; \
|
return ptr; \
|
||||||
} \
|
} \
|
||||||
inline void operator delete[](void *ptr) { \
|
inline void operator delete[](void *ptr) { \
|
||||||
|
if (ptr != nullptr) { \
|
||||||
PANDA_FREE_ARRAY(ptr); \
|
PANDA_FREE_ARRAY(ptr); \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
inline void operator delete[](void *, void *) { \
|
inline void operator delete[](void *, void *) { \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user