mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-23 12:00:21 +02:00
Fix leaky behavior of `scm_take_TAGvector ()'.
* libguile/srfi-4.c (free_user_data): New function. * libguile/srfi-4.i.c (scm_take_TAGvector): Register `free_user_data ()' as a finalizer for DATA. * libguile/objcodes.c (scm_objcode_to_bytecode): Allocate with `scm_malloc ()' since the memory taken by `scm_take_u8vector ()' will eventually be free(3)d. * libguile/vm.c (really_make_boot_program): Likewise.
This commit is contained in:
parent
ba54a2026b
commit
d7e7a02a62
4 changed files with 22 additions and 6 deletions
|
@ -229,8 +229,8 @@ SCM_DEFINE (scm_objcode_to_bytecode, "objcode->bytecode", 1, 0, 0,
|
|||
SCM_VALIDATE_OBJCODE (1, objcode);
|
||||
|
||||
len = sizeof(struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
|
||||
/* FIXME: Is `gc_malloc' ok here? */
|
||||
u8vector = scm_gc_malloc (len, "objcode-u8vector");
|
||||
|
||||
u8vector = scm_malloc (len);
|
||||
memcpy (u8vector, SCM_OBJCODE_DATA (objcode), len);
|
||||
|
||||
return scm_take_u8vector (u8vector, len);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "libguile/_scm.h"
|
||||
#include "libguile/__scm.h"
|
||||
#include "libguile/boehm-gc.h"
|
||||
#include "libguile/srfi-4.h"
|
||||
#include "libguile/bitvectors.h"
|
||||
#include "libguile/bytevectors.h"
|
||||
|
@ -281,6 +282,14 @@ uvec_assert (int type, SCM obj)
|
|||
scm_wrong_type_arg_msg (NULL, 0, obj, uvec_names[type]);
|
||||
}
|
||||
|
||||
/* Invoke free(3) on DATA, a user-provided buffer passed to one of the
|
||||
`scm_take_' functions. */
|
||||
static void
|
||||
free_user_data (GC_PTR data, GC_PTR unused)
|
||||
{
|
||||
free (data);
|
||||
}
|
||||
|
||||
static SCM
|
||||
take_uvec (int type, void *base, size_t len)
|
||||
{
|
||||
|
|
|
@ -126,8 +126,16 @@ SCM_DEFINE (F(scm_list_to_,TAG,vector), "list->"S(TAG)"vector", 1, 0, 0,
|
|||
SCM
|
||||
F(scm_take_,TAG,vector) (CTYPE *data, size_t n)
|
||||
{
|
||||
scm_gc_register_collectable_memory ((void *)data, n*uvec_sizes[TYPE],
|
||||
uvec_names[TYPE]);
|
||||
/* The manual says "Return a new uniform numeric vector [...] that uses the
|
||||
memory pointed to by DATA". We *have* to use DATA as the underlying
|
||||
storage; thus we must register a finalizer to eventually free(3) it. */
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalization_data;
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (data, free_user_data, 0,
|
||||
&prev_finalizer,
|
||||
&prev_finalization_data);
|
||||
|
||||
return take_uvec (TYPE, data, n);
|
||||
}
|
||||
|
||||
|
|
|
@ -190,8 +190,7 @@ really_make_boot_program (long nargs)
|
|||
abort ();
|
||||
text[1] = (scm_t_uint8)nargs;
|
||||
|
||||
bp = scm_gc_malloc (sizeof (struct scm_objcode) + sizeof (text),
|
||||
"make-u8vector");
|
||||
bp = scm_malloc (sizeof (struct scm_objcode) + sizeof (text));
|
||||
memcpy (bp->base, text, sizeof (text));
|
||||
bp->nargs = 0;
|
||||
bp->nrest = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue