1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

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.
This commit is contained in:
Ludovic Courtès 2022-11-20 18:07:24 +01:00
parent f72cd79152
commit e47a153317

View file

@ -1,4 +1,4 @@
/* Copyright 2001,2009-2015,2017-2020 /* Copyright 2001,2009-2015,2017-2020,2022
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of Guile. 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) scm_t_dynstack *dynstack, uint32_t flags)
{ {
struct scm_vm_cont *p; struct scm_vm_cont *p;
size_t stack_size;
p = scm_gc_malloc (sizeof (*p), "capture_vm_cont"); stack_size = stack_top - sp;
p->stack_size = stack_top - sp;
p->stack_bottom = scm_gc_malloc (p->stack_size * sizeof (*p->stack_bottom), /* 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"); "capture_vm_cont");
p->stack_size = stack_size;
p->stack_bottom = (void *) ((char *) p + sizeof (*p));
p->vra = vra; p->vra = vra;
p->mra = mra; p->mra = mra;
p->fp_offset = stack_top - fp; p->fp_offset = stack_top - fp;