cpython: 549d8d3297f2 (original) (raw)

Mercurial > cpython

changeset 84522:549d8d3297f2

Issue #18408: Fix _PyMem_DebugRealloc() Don't mark old extra memory dead before calling realloc(). realloc() can fail and realloc() must not touch the original buffer on failure. So mark old extra memory dead only on success if the new buffer did not move (has the same address). [#18408]

Victor Stinner victor.stinner@gmail.com
date Tue, 09 Jul 2013 00:44:43 +0200
parents d605c6b8095c
children c91e7f707562
files Objects/obmalloc.c
diffstat 1 files changed, 8 insertions(+), 6 deletions(-)[+] [-] Objects/obmalloc.c 14

line wrap: on

line diff

--- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -1780,7 +1780,7 @@ static void * _PyMem_DebugRealloc(void *ctx, void *p, size_t nbytes) { debug_alloc_api_t *api = (debug_alloc_api_t *)ctx;

- /* Resize and add decorations. We may get a new pointer here, in which * case we didn't get the chance to mark the old memory with DEADBYTE, * but we live with that. */

+ write_size_t(q, nbytes); assert(q[SST] == (uchar)api->api_id); for (i = 1; i < SST; ++i) assert(q[SST + i] == FORBIDDENBYTE); q += 2*SST; + tail = q + nbytes; memset(tail, FORBIDDENBYTE, SST); write_size_t(tail + SST, serialno);