bpo-36389: Change PyMem_SetupDebugHooks() constants (GH-12782)

Modify CLEANBYTE, DEADDYTE and FORBIDDENBYTE constants: use 0xCD,
0xDD and 0xFD, rather than 0xCB, 0xBB and 0xFB, to use the same byte
patterns than Windows CRT debug malloc() and free().
This commit is contained in:
Victor Stinner 2019-04-11 13:01:15 +02:00 committed by GitHub
parent 536a35b3f1
commit 4c409beb4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 24 deletions

View file

@ -160,21 +160,20 @@ PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
pointer value is checked.
The heuristic relies on the debug hooks on Python memory allocators which
fills newly allocated memory with CLEANBYTE (0xCB) and newly freed memory
with DEADBYTE (0xDB). Detect also "untouchable bytes" marked
with FORBIDDENBYTE (0xFB). */
fills newly allocated memory with CLEANBYTE (0xCD) and newly freed memory
with DEADBYTE (0xDD). Detect also "untouchable bytes" marked
with FORBIDDENBYTE (0xFD). */
static inline int _PyMem_IsPtrFreed(void *ptr)
{
uintptr_t value = (uintptr_t)ptr;
#if SIZEOF_VOID_P == 8
return (value == (uintptr_t)0xCBCBCBCBCBCBCBCB
|| value == (uintptr_t)0xDBDBDBDBDBDBDBDB
|| value == (uintptr_t)0xFBFBFBFBFBFBFBFB
);
return (value == (uintptr_t)0xCDCDCDCDCDCDCDCD
|| value == (uintptr_t)0xDDDDDDDDDDDDDDDD
|| value == (uintptr_t)0xFDFDFDFDFDFDFDFD);
#elif SIZEOF_VOID_P == 4
return (value == (uintptr_t)0xCBCBCBCB
|| value == (uintptr_t)0xDBDBDBDB
|| value == (uintptr_t)0xFBFBFBFB);
return (value == (uintptr_t)0xCDCDCDCD
|| value == (uintptr_t)0xDDDDDDDD
|| value == (uintptr_t)0xFDFDFDFD);
#else
# error "unknown pointer size"
#endif