From e47a153317c046ea5d335940412999e7dc604c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 20 Nov 2022 18:07:24 +0100 Subject: Work around unwanted stack retention when using prompts. Fixes . Previously, the stack allocated in 'capture_stack' and stored in 'p->stack_bottom' could be retained, leading to heap growth. * libguile/vm.c (capture_stack): Make a single 'scm_gc_malloc' call instead of two. --- libguile/vm.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libguile/vm.c b/libguile/vm.c index 6fd5c554f..b565db970 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -1,4 +1,4 @@ -/* Copyright 2001,2009-2015,2017-2020 +/* Copyright 2001,2009-2015,2017-2020,2022 Free Software Foundation, Inc. This file is part of Guile. @@ -165,11 +165,18 @@ capture_stack (union scm_vm_stack_element *stack_top, scm_t_dynstack *dynstack, uint32_t flags) { struct scm_vm_cont *p; + size_t stack_size; + + stack_size = stack_top - sp; + + /* Allocate the 'scm_vm_cont' struct and the stack at once. That way, + keeping a pointer to 'p->stack_bottom' around won't retain it. + See . */ + p = scm_gc_malloc (sizeof (*p) + stack_size * sizeof (*p->stack_bottom), + "capture_vm_cont"); - p = scm_gc_malloc (sizeof (*p), "capture_vm_cont"); - p->stack_size = stack_top - sp; - p->stack_bottom = scm_gc_malloc (p->stack_size * sizeof (*p->stack_bottom), - "capture_vm_cont"); + p->stack_size = stack_size; + p->stack_bottom = (void *) ((char *) p + sizeof (*p)); p->vra = vra; p->mra = mra; p->fp_offset = stack_top - fp; -- cgit v1.2.1