diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-31 12:05:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-31 12:05:03 (GMT) |
commit | b484d5606ca76f9bbd0f5de7a6ef753400213e94 (patch) | |
tree | c904a4502b4f44ae05a06c9c6e36c46a888d5b49 /Objects/obmalloc.c | |
parent | b9052a0f91d2e83bbc27267247a5920c82b242a3 (diff) | |
download | cpython-b484d5606ca76f9bbd0f5de7a6ef753400213e94.zip cpython-b484d5606ca76f9bbd0f5de7a6ef753400213e94.tar.gz cpython-b484d5606ca76f9bbd0f5de7a6ef753400213e94.tar.bz2 |
bpo-31626: Fixed a bug in debug memory allocator. (#3844)
Removed a code that incorrectly detected in-place resizing in realloc()
and wrote to freed memory.
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r-- | Objects/obmalloc.c | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index f2651d7..1485172 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -1460,7 +1460,7 @@ static void * _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) { debug_alloc_api_t *api = (debug_alloc_api_t *)ctx; - uint8_t *q = (uint8_t *)p, *oldq; + uint8_t *q = (uint8_t *)p; uint8_t *tail; size_t total; /* nbytes + 4*SST */ size_t original_nbytes; @@ -1477,20 +1477,11 @@ _PyMem_DebugRawRealloc(void *ctx, void *p, size_t nbytes) /* overflow: can't represent total as a Py_ssize_t */ return NULL; - /* 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. - */ - oldq = q; + /* Resize and add decorations. */ q = (uint8_t *)api->alloc.realloc(api->alloc.ctx, q - 2*SST, total); if (q == NULL) return NULL; - if (q == oldq && nbytes < original_nbytes) { - /* shrinking: mark old extra memory dead */ - memset(q + nbytes, DEADBYTE, original_nbytes - nbytes); - } - write_size_t(q, nbytes); assert(q[SST] == (uint8_t)api->api_id); for (i = 1; i < SST; ++i) |