]> granicus.if.org Git - gc/commitdiff
2011-03-13 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Sun, 13 Mar 2011 13:08:16 +0000 (13:08 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:56 +0000 (21:06 +0400)
* dbg_mlc.c (GC_make_closure): Fix SEGV in case GC_malloc returns
NULL.
* dbg_mlc.c (GC_debug_register_finalizer,
GC_debug_register_finalizer_no_order,
GC_debug_register_finalizer_unreachable,
GC_debug_register_finalizer_ignore_self): Handle out of memory
case properly (similar to GC_register_finalizer_inner).
* headers.c (GC_install_header): Handle the case when alloc_hdr()
returns NULL.
* os_dep.c (GC_get_maps_len): Defend against missing "maps" file.
* pthread_support.c (GC_mark_thread): Place a dummy return
statement (which uses "id" argument) before the actual use of "id"
as an array index (to suppress a warning produced by some static
code analysis tools).
* win32_threads.c (GC_mark_thread): Ditto.
* pthread_support.c (GC_thr_init): Abort (with the appropriate
message) if out of memory.

ChangeLog
dbg_mlc.c
headers.c
os_dep.c
pthread_support.c
win32_threads.c

index 3c3b61df5552b716723b4e80c2298e88e58813bd..084512847fef6962129432414a3644265f4aa7c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2011-03-13  Ivan Maidanski  <ivmai@mail.ru>
+
+       * dbg_mlc.c (GC_make_closure): Fix SEGV in case GC_malloc returns
+       NULL.
+       * dbg_mlc.c (GC_debug_register_finalizer,
+       GC_debug_register_finalizer_no_order,
+       GC_debug_register_finalizer_unreachable,
+       GC_debug_register_finalizer_ignore_self): Handle out of memory
+       case properly (similar to GC_register_finalizer_inner).
+       * headers.c (GC_install_header): Handle the case when alloc_hdr()
+       returns NULL.
+       * os_dep.c (GC_get_maps_len): Defend against missing "maps" file.
+       * pthread_support.c (GC_mark_thread): Place a dummy return
+       statement (which uses "id" argument) before the actual use of "id"
+       as an array index (to suppress a warning produced by some static
+       code analysis tools).
+       * win32_threads.c (GC_mark_thread): Ditto.
+       * pthread_support.c (GC_thr_init): Abort (with the appropriate
+       message) if out of memory.
+
 2011-03-13  Ivan Maidanski  <ivmai@mail.ru>
 
        * finalize.c (GC_register_finalizer_inner): Fix a typo in a
index 1de97ff85eab3ddf6e3c9633e8e5622baf782791..29e9a898c61563a61d0ba7189e5f06c0d705d270 100644 (file)
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -96,7 +96,7 @@ GC_API void GC_CALL GC_register_finalizer_no_order(void * obj,
   /*   Returns 1 on success, 0 if source couldn't be determined.        */
   /* Dest can be any address within a heap object.                      */
   GC_API GC_ref_kind GC_CALL GC_get_back_ptr_info(void *dest, void **base_p,
-                                                size_t *offset_p)
+                                                  size_t *offset_p)
   {
     oh * hdr = (oh *)GC_base(dest);
     ptr_t bp;
@@ -774,8 +774,8 @@ GC_API void GC_CALL GC_debug_free(void * p)
     ptr_t base = GC_base(p);
     GC_ASSERT((ptr_t)p - (ptr_t)base == sizeof(oh));
 #   ifndef SHORT_DBG_HDRS
-    /* Invalidate size */
-        ((oh *)base) -> oh_sz = GC_size(base);
+      /* Invalidate size */
+      ((oh *)base) -> oh_sz = GC_size(base);
 #   endif
     GC_free_inner(base);
   }
@@ -939,9 +939,10 @@ STATIC void * GC_make_closure(GC_finalization_proc fn, void * data)
 #   else
       (struct closure *) GC_malloc(sizeof (struct closure));
 #   endif
-
-    result -> cl_fn = fn;
-    result -> cl_data = data;
+    if (result != 0) {
+      result -> cl_fn = fn;
+      result -> cl_data = data;
+    }
     return((void *)result);
 }
 
@@ -1002,8 +1003,10 @@ GC_API void GC_CALL GC_debug_register_finalizer(void * obj,
     if (0 == fn) {
       GC_register_finalizer(base, 0, 0, &my_old_fn, &my_old_cd);
     } else {
+      cd = GC_make_closure(fn, cd);
+      if (cd == 0) return; /* out of memory */
       GC_register_finalizer(base, GC_debug_invoke_finalizer,
-                            GC_make_closure(fn,cd), &my_old_fn, &my_old_cd);
+                            cd, &my_old_fn, &my_old_cd);
     }
     store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
 }
@@ -1031,9 +1034,10 @@ GC_API void GC_CALL GC_debug_register_finalizer_no_order
     if (0 == fn) {
       GC_register_finalizer_no_order(base, 0, 0, &my_old_fn, &my_old_cd);
     } else {
+      cd = GC_make_closure(fn, cd);
+      if (cd == 0) return; /* out of memory */
       GC_register_finalizer_no_order(base, GC_debug_invoke_finalizer,
-                                     GC_make_closure(fn,cd), &my_old_fn,
-                                     &my_old_cd);
+                                     cd, &my_old_fn, &my_old_cd);
     }
     store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
 }
@@ -1061,9 +1065,10 @@ GC_API void GC_CALL GC_debug_register_finalizer_unreachable
     if (0 == fn) {
       GC_register_finalizer_unreachable(base, 0, 0, &my_old_fn, &my_old_cd);
     } else {
+      cd = GC_make_closure(fn, cd);
+      if (cd == 0) return; /* out of memory */
       GC_register_finalizer_unreachable(base, GC_debug_invoke_finalizer,
-                                        GC_make_closure(fn,cd), &my_old_fn,
-                                        &my_old_cd);
+                                        cd, &my_old_fn, &my_old_cd);
     }
     store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
 }
@@ -1090,9 +1095,10 @@ GC_API void GC_CALL GC_debug_register_finalizer_ignore_self
     if (0 == fn) {
       GC_register_finalizer_ignore_self(base, 0, 0, &my_old_fn, &my_old_cd);
     } else {
+      cd = GC_make_closure(fn, cd);
+      if (cd == 0) return; /* out of memory */
       GC_register_finalizer_ignore_self(base, GC_debug_invoke_finalizer,
-                                        GC_make_closure(fn,cd), &my_old_fn,
-                                        &my_old_cd);
+                                        cd, &my_old_fn, &my_old_cd);
     }
     store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
 }
index 1f8a7c973d9d67ba302abaa3c2ed32759596e4c7..c4f5023caaaff9e536282ea44354912521395558 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -261,10 +261,12 @@ GC_INNER struct hblkhdr * GC_install_header(struct hblk *h)
 
     if (!get_index((word) h)) return(0);
     result = alloc_hdr();
-    SET_HDR(h, result);
-#   ifdef USE_MUNMAP
+    if (result) {
+      SET_HDR(h, result);
+#     ifdef USE_MUNMAP
         result -> hb_last_reclaimed = (unsigned short)GC_gc_no;
-#   endif
+#     endif
+    }
     return(result);
 }
 
index 768ab451798f2727a688e6aaa3d1b064bfa17a2d..0b9813ed0962ee54a7735c09884455c8835d7f19 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -189,7 +189,9 @@ STATIC ssize_t GC_repeat_read(int fd, char *buf, size_t count)
   STATIC size_t GC_get_maps_len(void)
   {
     int f = open("/proc/self/maps", O_RDONLY);
-    size_t result = GC_get_file_len(f);
+    size_t result;
+    if (f < 0) return 0; /* treat missing file as empty */
+    result = GC_get_file_len(f);
     close(f);
     return result;
   }
@@ -227,9 +229,9 @@ GC_INNER char * GC_get_maps(void)
     /* This only matters with threads enabled, and if we use    */
     /* this to locate roots (not the default).                  */
 
-    /* Determine the initial size of /proc/self/maps.           */
-    /* Note that lseek doesn't work, at least as of 2.6.15.     */
 #   ifdef THREADS
+        /* Determine the initial size of /proc/self/maps.       */
+        /* Note that lseek doesn't work, at least as of 2.6.15. */
         maps_size = GC_get_maps_len();
         if (0 == maps_size) return 0;
 #   else
index 2cd012de885dc1d6e5cfca3832044828a380dee6..d592bba0da7a3c6af69822b37c14ea67dddf913b 100644 (file)
@@ -363,6 +363,7 @@ STATIC void * GC_mark_thread(void * id)
   word my_mark_no = 0;
   IF_CANCEL(int cancel_state;)
 
+  if ((word)id == (word)-1) return 0; /* to make compiler happy */
   DISABLE_CANCEL(cancel_state);
                          /* Mark threads are not cancellable; they      */
                          /* should be invisible to client.              */
@@ -374,8 +375,6 @@ STATIC void * GC_mark_thread(void * id)
     marker_mach_threads[(word)id] = mach_thread_self();
 # endif
 
-  if ((word)id == (word)-1) return 0; /* to make compiler happy */
-
   for (;; ++my_mark_no) {
     /* GC_mark_no is passed only to allow GC_help_marker to terminate   */
     /* promptly.  This is important if it were called from the signal   */
@@ -921,6 +920,8 @@ GC_INNER void GC_thr_init(void)
   /* Add the initial thread, so we can stop it. */
   {
     GC_thread t = GC_new_thread(pthread_self());
+    if (t == NULL)
+      ABORT("Failed to allocate memory for the initial thread.");
 #   ifdef GC_DARWIN_THREADS
       t -> stop_info.mach_thread = mach_thread_self();
 #   else
index f7f74ea32ffd0bdf49667c1f725a8c02f4b54d74..99fc14cbe87ddf794dd8b324ce1a2da8261f8e26 100644 (file)
@@ -1500,13 +1500,12 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
   {
     word my_mark_no = 0;
 
+    if ((word)id == (word)-1) return 0; /* to make compiler happy */
     marker_sp[(word)id] = GC_approx_sp();
 #   ifdef IA64
       marker_bsp[(word)id] = GC_save_regs_in_stack();
 #   endif
 
-    if ((word)id == (word)-1) return 0; /* to make compiler happy */
-
     for (;; ++my_mark_no) {
       if (my_mark_no - GC_mark_no > (word)2) {
         /* resynchronize if we get far off, e.g. because GC_mark_no     */