bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #34029] mem leak in objcodes.c and vm.c


From: Stefan Israelsson Tampe
Subject: [bug #34029] mem leak in objcodes.c and vm.c
Date: Tue, 16 Aug 2011 20:25:36 +0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101216 Linux Mint/1 (Debian) Firefox/3.6.13

URL:
  <http://savannah.gnu.org/bugs/?34029>

                 Summary: mem leak in objcodes.c and vm.c
                 Project: Guile
            Submitted by: tampe
            Submitted on: Tue 16 Aug 2011 08:25:35 PM GMT
                Category: None
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

>>>>>>>>>>>> Consider the following code,

SCM_DEFINE (scm_objcode_to_bytecode, "objcode->bytecode", 1, 0, 0,
            (SCM objcode),
            "")
#define FUNC_NAME s_scm_objcode_to_bytecode
{
  scm_t_int8 *s8vector;
  scm_t_uint32 len;

  SCM_VALIDATE_OBJCODE (1, objcode);

  len = sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);

(0)  s8vector = scm_malloc (len);
  memcpy (s8vector, SCM_OBJCODE_DATA (objcode), len);

(1) return scm_c_take_bytevector (s8vector, len);
}
#undef FUNC_NAME
-------------------------------------------------
(0) allocates s8vector using scm_malloc!
(1) scm_c_take_bytevector put s8vector into a bytevector

>>>>>>>>>>>> But in bytevector.c,
/
* Return a bytevector of size LEN made up of CONTENTS.  The area pointed to
   by CONTENTS must have been allocated using `scm_gc_malloc ()'.  */
SCM
scm_c_take_bytevector (signed char *contents, size_t len)
{
  return make_bytevector_from_buffer (len, contents,
SCM_ARRAY_ELEMENT_TYPE_VU8);
}
-------------------------------------------------------------
scm_malloc does not allocate memory controlled by the gc and 
hece the gc will not free up the scm_malloced block! should be
scm_gc_malloc_pointerless instead.
*************************************************************
>>>>>>>>>>>>>> Also in vm.c,
static SCM
really_make_boot_program (long nargs)
{
  SCM u8vec;
  scm_t_uint8 text[] = { scm_op_mv_call, 0, 0, 0, 1,
                         scm_op_make_int8_1, scm_op_halt };
  struct scm_objcode *bp;
  SCM ret;

  if (SCM_UNLIKELY (nargs > 255 || nargs < 0))
    scm_misc_error ("vm-engine", "too many args when making boot procedure",
                    scm_list_1 (scm_from_long (nargs)));

  text[1] = (scm_t_uint8)nargs;

 (0) bp = scm_malloc (sizeof (struct scm_objcode) + sizeof (text));
  memcpy (SCM_C_OBJCODE_BASE (bp), text, sizeof (text));
  bp->len = sizeof(text);
  bp->metalen = 0;

 (1) u8vec = scm_c_take_bytevector ((scm_t_int8*)bp,
                                 sizeof (struct scm_objcode) + sizeof
(text));
  ret = scm_make_program (scm_bytecode_to_objcode (u8vec),
                          SCM_BOOL_F, SCM_BOOL_F);
  SCM_SET_CELL_WORD_0 (ret, SCM_CELL_WORD_0 (ret) | SCM_F_PROGRAM_IS_BOOT);

  return ret;
}
-------------------------------------------
(0),(1) the same suspect logic appears again (0) should 
contain scm_gc_malloc_pointerless




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?34029>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]