guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Fixed `scm_i_take_stringbufn ()'


From: Ludovic Courtès
Subject: Re: [PATCH] Fixed `scm_i_take_stringbufn ()'
Date: Tue, 14 Feb 2006 10:47:30 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Hi,

Kevin Ryde <address@hidden> writes:

> The `if' you put, with an fprintf stderr, should be fine.

I think you're right.  Here's the updated patch.

Thanks,
Ludovic.


2006-02-14  Ludovic Courtès  <address@hidden>

        *strings.c (scm_i_take_stringbufn): Register LEN + 1 octets
        instead of LEN.  Without this, too much collectable memory gets
        unregistered, which results in an underflow of SCM_MALLOCATED in
        `decrease_mtrigger ()'.

        * gc-malloc.c (decrease_mtrigger): Make sure SIZE is lower than
        or equal to SCM_MALLOCATED.


--- orig/libguile/gc-malloc.c
+++ mod/libguile/gc-malloc.c
@@ -64,6 +64,7 @@
 #include <unistd.h>
 #endif
 
+
 /*
   INIT_MALLOC_LIMIT is the initial amount of malloc usage which will
   trigger a GC.
@@ -184,6 +185,16 @@
 decrease_mtrigger (size_t size, const char * what)
 {
   scm_i_pthread_mutex_lock (&scm_i_gc_admin_mutex);
+
+  if (size > scm_mallocated)
+    {
+      fprintf (stderr, "`scm_mallocated' underflow.  This means that more "
+              "memory was unregistered\n"
+              "via `scm_gc_unregister_collectable_memory ()' than "
+              "registered.\n");
+      abort ();
+    }
+
   scm_mallocated -= size;
   scm_gc_malloc_collected += size;
   scm_i_pthread_mutex_unlock (&scm_i_gc_admin_mutex);


--- orig/libguile/strings.c
+++ mod/libguile/strings.c
@@ -122,12 +122,12 @@
     }
 }
 
-/* Return a new stringbuf whose underlying storage consists of the LEN octets
-   pointed to by STR.  */
+/* Return a new stringbuf whose underlying storage consists of the LEN+1
+   octets pointed to by STR (the last octet is zero).  */
 SCM_C_INLINE SCM
 scm_i_take_stringbufn (char *str, size_t len)
 {
-  scm_gc_register_collectable_memory (str, len, "stringbuf");
+  scm_gc_register_collectable_memory (str, len + 1, "stringbuf");
 
   return scm_double_cell (STRINGBUF_TAG, (scm_t_bits) str,
                          (scm_t_bits) len, (scm_t_bits) 0);





reply via email to

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