fix a couple of leaks
authorAndy Wingo <wingo@pobox.com>
Thu, 18 Aug 2011 09:54:20 +0000 (11:54 +0200)
committerAndy Wingo <wingo@pobox.com>
Thu, 18 Aug 2011 10:53:28 +0000 (12:53 +0200)
* libguile/bytevectors.h:
* libguile/bytevectors.c (scm_c_take_gc_bytevector): Rename this
  internal function, from scm_c_take_bytevector.  This indicates that
  unlike the other scm_take_* functions, this one takes GC-managed
  memory.

* libguile/objcodes.c (scm_objcode_to_bytecode):
* libguile/vm.c (really_make_boot_program): Use
  scm_gc_malloc_pointerless, not scm_malloc.  Thanks to Stefan
  Israelsson Tampe!

* libguile/r6rs-ports.c:
* libguile/strings.c: Adapt to renames.

libguile/bytevectors.c
libguile/bytevectors.h
libguile/objcodes.c
libguile/r6rs-ports.c
libguile/strings.c
libguile/vm.c

index 14159d2..4aeae63 100644 (file)
@@ -285,7 +285,7 @@ scm_i_make_typed_bytevector (size_t len, scm_t_array_element_type element_type)
 /* 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)
+scm_c_take_gc_bytevector (signed char *contents, size_t len)
 {
   return make_bytevector_from_buffer (len, contents, SCM_ARRAY_ELEMENT_TYPE_VU8);
 }
index 431b7dd..8bafff3 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SCM_BYTEVECTORS_H
 #define SCM_BYTEVECTORS_H
 
-/* Copyright (C) 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2009, 2011 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -138,7 +138,7 @@ SCM_INTERNAL void scm_bootstrap_bytevectors (void);
 SCM_INTERNAL void scm_init_bytevectors (void);
 
 SCM_INTERNAL SCM scm_i_native_endianness;
-SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
+SCM_INTERNAL SCM scm_c_take_gc_bytevector (signed char *, size_t);
 
 SCM_INTERNAL int scm_i_print_bytevector (SCM, SCM, scm_print_state *);
 
index 526751a..6223362 100644 (file)
@@ -315,10 +315,10 @@ SCM_DEFINE (scm_objcode_to_bytecode, "objcode->bytecode", 1, 0, 0,
 
   len = sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
 
-  s8vector = scm_malloc (len);
+  s8vector = scm_gc_malloc_pointerless (len, FUNC_NAME);
   memcpy (s8vector, SCM_OBJCODE_DATA (objcode), len);
 
-  return scm_c_take_bytevector (s8vector, len);
+  return scm_c_take_gc_bytevector (s8vector, len);
 }
 #undef FUNC_NAME
 
index 6eff97d..e867429 100644 (file)
@@ -618,7 +618,7 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevector-some", 1, 0, 0,
          c_len = (unsigned) c_total;
        }
 
-      result = scm_c_take_bytevector ((signed char *) c_bv, c_len);
+      result = scm_c_take_gc_bytevector ((signed char *) c_bv, c_len);
     }
 
   return result;
@@ -677,7 +677,7 @@ SCM_DEFINE (scm_get_bytevector_all, "get-bytevector-all", 1, 0, 0,
          c_len = (unsigned) c_total;
        }
 
-      result = scm_c_take_bytevector ((signed char *) c_bv, c_len);
+      result = scm_c_take_gc_bytevector ((signed char *) c_bv, c_len);
     }
 
   return result;
@@ -919,7 +919,7 @@ SCM_SMOB_APPLY (bytevector_output_port_procedure,
   bop_buffer_init (buf);
 
   if (result_buf.len == 0)
-    bv = scm_c_take_bytevector (NULL, 0);
+    bv = scm_c_take_gc_bytevector (NULL, 0);
   else
     {
       if (result_buf.total_len > result_buf.len)
@@ -929,8 +929,8 @@ SCM_SMOB_APPLY (bytevector_output_port_procedure,
                                            result_buf.len,
                                            SCM_GC_BOP);
 
-      bv = scm_c_take_bytevector ((signed char *) result_buf.buffer,
-                                      result_buf.len);
+      bv = scm_c_take_gc_bytevector ((signed char *) result_buf.buffer,
+                                     result_buf.len);
     }
 
   return bv;
index 24c82fc..5b15ddc 100644 (file)
@@ -1489,7 +1489,7 @@ scm_from_stringn (const char *str, size_t len, const char *encoding,
 
       buf = scm_gc_malloc_pointerless (len, "bytevector");
       memcpy (buf, str, len);
-      bv = scm_c_take_bytevector (buf, len);
+      bv = scm_c_take_gc_bytevector (buf, len);
 
       scm_decoding_error (__func__, errno,
                          "input locale conversion error", bv);
index b9d613a..6cb85b7 100644 (file)
@@ -384,13 +384,14 @@ really_make_boot_program (long nargs)
 
   text[1] = (scm_t_uint8)nargs;
 
-  bp = scm_malloc (sizeof (struct scm_objcode) + sizeof (text));
+  bp = scm_gc_malloc_pointerless (sizeof (struct scm_objcode) + sizeof (text),
+                                  "boot-program");
   memcpy (SCM_C_OBJCODE_BASE (bp), text, sizeof (text));
   bp->len = sizeof(text);
   bp->metalen = 0;
 
-  u8vec = scm_c_take_bytevector ((scm_t_int8*)bp,
-                                 sizeof (struct scm_objcode) + sizeof (text));
+  u8vec = scm_c_take_gc_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);