diff options
author | Ludovic Courtès <ludo@gnu.org> | 2022-11-20 18:07:24 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-11-20 18:07:24 +0100 |
commit | e47a153317c046ea5d335940412999e7dc604c33 (patch) | |
tree | 15b7567fcba04e8fd65909799b56e38604cd2e0a | |
parent | f72cd791520ee3015a8b7d4e5059b3ed7a1f24bd (diff) | |
download | guile-e47a153317c046ea5d335940412999e7dc604c33.tar.gz |
Work around unwanted stack retention when using prompts.
Fixes <https://bugs.gnu.org/59021>.
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.
-rw-r--r-- | libguile/vm.c | 17 |
1 files 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 <https://bugs.gnu.org/59021>. */ + 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; |