From 0ba2d17fafb81ee6f29ec1cc4cc3bef6859934c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20B=C3=A1tyai?= Date: Fri, 17 May 2019 11:28:00 +0200 Subject: [PATCH] Fix heap limit calculation when using the system allocator. (#2872) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu --- jerry-core/jmem/jmem-heap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/jerry-core/jmem/jmem-heap.c b/jerry-core/jmem/jmem-heap.c index e7e9906d6..58e86100f 100644 --- a/jerry-core/jmem/jmem-heap.c +++ b/jerry-core/jmem/jmem-heap.c @@ -283,6 +283,13 @@ jmem_heap_alloc_block_internal (const size_t size) /**< size of requested block return (void *) data_space_p; #else /* JERRY_SYSTEM_ALLOCATOR */ JMEM_HEAP_STAT_ALLOC (size); + JERRY_CONTEXT (jmem_heap_allocated_size) += size; + + while (JERRY_CONTEXT (jmem_heap_allocated_size) >= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) += CONFIG_MEM_HEAP_DESIRED_LIMIT; + } + return malloc (size); #endif /* !JERRY_SYSTEM_ALLOCATOR */ } /* jmem_heap_alloc_block_internal */ @@ -487,6 +494,13 @@ jmem_heap_free_block (void *ptr, /**< pointer to beginning of data space of the JMEM_HEAP_STAT_FREE (size); #else /* JERRY_SYSTEM_ALLOCATOR */ JMEM_HEAP_STAT_FREE (size); + JERRY_CONTEXT (jmem_heap_allocated_size) -= size; + + while (JERRY_CONTEXT (jmem_heap_allocated_size) + CONFIG_MEM_HEAP_DESIRED_LIMIT <= JERRY_CONTEXT (jmem_heap_limit)) + { + JERRY_CONTEXT (jmem_heap_limit) -= CONFIG_MEM_HEAP_DESIRED_LIMIT; + } + free (ptr); #endif /* !JERRY_SYSTEM_ALLOCATOR */ } /* jmem_heap_free_block */