Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 25, 2017

Fix memory debug hooks on OpenBSD: fix _PyMem_DebugRawRealloc().
Previously, the old resized memory block was modified after realloc()
success to fill now unused bytes with the DEADBYTE pattern. On
OpenBSD, modifying the old memory block causes a fatal error.

On OpenBSD, the function now erases the bytes before calling
realloc(), but keep a copy of erased bytes to restore them if
realloc() fails.

The behaviour on other platforms is unchanged: erased bytes after
realloc() success.

Co-Authored-By: Serhiy Storchaka storchaka@gmail.com

https://bugs.python.org/issue31626

Fix memory debug hooks on OpenBSD: fix _PyMem_DebugRawRealloc().
Previously, the old resized memory block was modified after realloc()
success to fill now unused bytes with the DEADBYTE pattern. On
OpenBSD, modifying the old memory block causes a fatal error.

On OpenBSD, the function now erases the bytes *before* calling
realloc(), but keep a copy of erased bytes to restore them if
realloc() fails.

The behaviour on other platforms is unchanged: erased bytes *after*
realloc() success.

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
memory block on realloc() success: the program is killed by a fatal
trap signal. So erase bytes before, but keep a copy to restore erased
bytes if realloc() fails. */
# define REALLOC_WRITE_BEFORE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be simpler to modify _PyMem_DebugRawRealloc() to behave "correctly" on all platforms. What do you think?

I don't think that the "copy" memory allocation is a real blocker issue. It's a debug hook, I consider that the memory usage is not a big deal here.

@vstinner
Copy link
Member Author

@serhiy-storchaka merged a simpler fix: PR #3844.

@vstinner vstinner closed this Oct 31, 2017
@vstinner vstinner deleted the debug_realloc branch October 31, 2017 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants