2011-04-09 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Sat, 9 Apr 2011 13:42:08 +0000 (13:42 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:57 +0000 (21:06 +0400)
* reclaim.c (GC_print_all_errors): Recognize new GC_ABORT_ON_LEAK
macro and environment variable; abort if any error has been
printed provided the environment variable (or macro) is set.
* doc/README.environment (GC_ABORT_ON_LEAK): Document.
* doc/README.macros (GC_ABORT_ON_LEAK): Ditto.
* doc/README.macros (FIND_LEAK, SUNOS5SIGS, PCR,
USE_COMPILER_TLS): Reformat the text.

ChangeLog
doc/README.environment
doc/README.macros
reclaim.c

index ec8e719..d54087d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2011-04-09  Ivan Maidanski  <ivmai@mail.ru>
 
+       * reclaim.c (GC_print_all_errors): Recognize new GC_ABORT_ON_LEAK
+       macro and environment variable; abort if any error has been
+       printed provided the environment variable (or macro) is set.
+       * doc/README.environment (GC_ABORT_ON_LEAK): Document.
+       * doc/README.macros (GC_ABORT_ON_LEAK): Ditto.
+       * doc/README.macros (FIND_LEAK, SUNOS5SIGS, PCR,
+       USE_COMPILER_TLS): Reformat the text.
+
+2011-04-09  Ivan Maidanski  <ivmai@mail.ru>
+
        * os_dep.c (GC_unix_sbrk_get_mem, GC_unix_get_mem): Don't define
        for RTEMS.
        * include/private/gcconfig.h (RTEMS): Add support for.
index ef7c7cb..ce12067 100644 (file)
@@ -158,6 +158,9 @@ GC_FIND_LEAK - Turns on GC_find_leak and thus leak detection.  Forces a
                collection at program termination to detect leaks that would
                otherwise occur after the last GC.
 
+GC_ABORT_ON_LEAK - Causes the application to be terminated once leaked or
+                   smashed objects are found.
+
 GC_ALL_INTERIOR_POINTERS - Turns on GC_all_interior_pointers and thus interior
                            pointer recognition.
 
index 1b49200..c995117 100644 (file)
@@ -81,23 +81,27 @@ GC_REQUIRE_WCSDUP       Force GC to export GC_wcsdup() (the Unicode version
 
 
 These define arguments influence the collector configuration:
-FIND_LEAK causes GC_find_leak to be initially set.
-  This causes the collector to assume that all inaccessible
-  objects should have been explicitly deallocated, and reports exceptions.
-  Finalization and the test program are not usable in this mode.
+
+FIND_LEAK      Causes GC_find_leak to be initially set.  This causes the
+  collector to assume that all inaccessible objects should have been
+  explicitly deallocated, and reports exceptions.  Finalization and the test
+  program are not usable in this mode.
+
+GC_ABORT_ON_LEAK       Causes the application to be terminated once leaked or
+  smashed (corrupted on use-after-free) objects are found (after printing the
+  information about that objects).
 
 SUNOS5SIGS      Solaris-like signal handling.  This is probably misnamed,
-                since it really doesn't guarantee much more than Posix.
-                Currently set only for Solaris2.X, HPUX, and DRSNX.  Should
-                probably be set for some other platforms.
+  since it really doesn't guarantee much more than POSIX.  Currently set only
+  for Solaris2.X, HPUX, and DRSNX.  Should probably be set for some other
+  platforms.
 
-PCR             Set if the collector is being built as part of the Xerox
-                Portable Common Runtime.
+PCR    Set if the collector is being built as part of the Xerox Portable
+  Common Runtime.
 
-USE_COMPILER_TLS  Assume the existence of __thread-style thread-local
-                storage.  Set automatically for thread-local allocation with
-                the HP/UX vendor compiler.  Usable with gcc on sufficiently
-                up-to-date ELF platforms.
+USE_COMPILER_TLS  Assume the existence of __thread-style thread-local storage.
+  Set automatically for thread-local allocation with the HP/UX vendor
+  compiler.  Usable with gcc on sufficiently up-to-date ELF platforms.
 
 IMPORTANT: Any of the _THREADS options must normally also be defined in
   the client before including gc.h.  This redefines thread primitives to
index e17d374..efade9b 100644 (file)
--- a/reclaim.c
+++ b/reclaim.c
@@ -57,6 +57,7 @@ STATIC void GC_add_leaked(ptr_t leaked)
 GC_INNER void GC_print_all_errors(void)
 {
     static GC_bool printing_errors = FALSE;
+    GC_bool have_errors;
     unsigned i;
     DCL_LOCK_STATE;
 
@@ -65,9 +66,16 @@ GC_INNER void GC_print_all_errors(void)
         UNLOCK();
         return;
     }
+    have_errors = GC_have_errors;
     printing_errors = TRUE;
     UNLOCK();
-    if (GC_debugging_started) GC_print_all_smashed();
+
+    if (GC_debugging_started) {
+      GC_print_all_smashed();
+    } else {
+      have_errors = FALSE;
+    }
+
     for (i = 0; i < GC_n_leaked; ++i) {
         ptr_t p = GC_leaked[i];
         if (HDR(p) -> hb_obj_kind == PTRFREE) {
@@ -79,8 +87,18 @@ GC_INNER void GC_print_all_errors(void)
         GC_err_printf("\n");
         GC_free(p);
         GC_leaked[i] = 0;
+        have_errors = TRUE;
     }
     GC_n_leaked = 0;
+
+    if (have_errors
+#       ifndef GC_ABORT_ON_LEAK
+          && GETENV("GC_ABORT_ON_LEAK") != NULL
+#       endif
+        ) {
+      ABORT("Leaked or smashed objects encountered");
+    }
+
     printing_errors = FALSE;
 }