From d6c558c0aae53d3cd5f8871394f44bd23836307e Mon Sep 17 00:00:00 2001 From: Damien George <damien.p.george@gmail.com> Date: Tue, 23 Feb 2016 13:44:29 +0000 Subject: [PATCH] py/parse: Use m_renew_maybe to ensure that memory is shrunk in-place. The chunks of memory that the parser allocates contain parse nodes and are pointed to from many places, so these chunks cannot be relocated by the memory manager. This patch makes it so that when a chunk is shrunk to fit, it is not relocated. --- py/parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/parse.c b/py/parse.c index bbe5b038a..d1f29139a 100644 --- a/py/parse.c +++ b/py/parse.c @@ -166,8 +166,8 @@ STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) { sizeof(mp_parse_chunk_t) + chunk->alloc + num_bytes, false); if (new_data == NULL) { // could not grow existing memory; shrink it to fit previous - (void)m_renew(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc, - sizeof(mp_parse_chunk_t) + chunk->union_.used); + (void)m_renew_maybe(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc, + sizeof(mp_parse_chunk_t) + chunk->union_.used, false); chunk->alloc = chunk->union_.used; chunk->union_.next = parser->tree.chunk; parser->tree.chunk = chunk; -- GitLab