]> granicus.if.org Git - gc/commitdiff
Fix GC_scratch_alloc and GC_get_maps invocations to prevent SEGV
authorIvan Maidanski <ivmai@mail.ru>
Thu, 7 Jun 2012 18:00:37 +0000 (22:00 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 7 Jun 2012 18:00:37 +0000 (22:00 +0400)
(if out of memory)

* dyn_load.c (GC_register_dynamic_libraries): If GC_scratch_alloc
fails (returns null) then abort (with the appropriate message) instead
of causing SEGV.
* os_dep.c (GC_dirty_init): Likewise.
* headers.c (GC_init_headers): Report error and exit if
GC_scratch_alloc fails.
* include/private/gc_priv.h (GC_scratch_alloc): Improve comment.
* os_dep.c (GC_print_address_map): If GC_get_maps return null then
print the appropriate message (instead of passing null to GC_err_puts
thus causing SEGV).

dyn_load.c
headers.c
include/private/gc_priv.h
os_dep.c

index e76c88807da3d2688d8a10d92b7e2ad91156eb44..b521806ccdee36285e20a990e9eb5f09c975f4ee 100644 (file)
@@ -758,6 +758,8 @@ GC_INNER void GC_register_dynamic_libraries(void)
                         /* Expansion, plus room for 0 record */
         addr_map = (prmap_t *)GC_scratch_alloc(
                                 (word)current_sz * sizeof(prmap_t));
+        if (addr_map == NULL)
+          ABORT("Insufficient memory for address map");
     }
     if (ioctl(fd, PIOCMAP, addr_map) < 0) {
         GC_err_printf("fd = %d, errno = %d, needed_sz = %d, addr_map = %p\n",
index 71ab29f5c8811a888aba93d1374c7e0fb787bba1..47cc526e905218379a3b71bf3cb1e95e7fc73ea5 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -196,6 +196,10 @@ GC_INNER void GC_init_headers(void)
     register unsigned i;
 
     GC_all_nils = (bottom_index *)GC_scratch_alloc((word)sizeof(bottom_index));
+    if (GC_all_nils == NULL) {
+      GC_err_printf("Insufficient memory for GC_all_nils\n");
+      EXIT();
+    }
     BZERO(GC_all_nils, sizeof(bottom_index));
     for (i = 0; i < TOP_SZ; i++) {
         GC_top_index[i] = GC_all_nils;
index 2809f063182363a70cd571a9025d40c2bb0a7e90..f7641deadb688c64a8db87a76ad3640bbe38dfd6 100644 (file)
@@ -1668,7 +1668,7 @@ GC_INNER void GC_unpromote_black_lists(void);
 GC_INNER ptr_t GC_scratch_alloc(size_t bytes);
                                 /* GC internal memory allocation for    */
                                 /* small objects.  Deallocation is not  */
-                                /* possible.                            */
+                                /* possible.  May return NULL.          */
 
 /* Heap block layout maps: */
 GC_INNER GC_bool GC_add_map_entry(size_t sz);
index 3dea9482cb3190ebc1a22e056ab102cae12c941d..4fb24eb51789089d9124e38052fcc104231909e8 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -3686,6 +3686,8 @@ GC_INNER void GC_dirty_init(void)
 
     GC_dirty_maintained = TRUE;
     GC_proc_buf = GC_scratch_alloc(GC_proc_buf_size);
+    if (GC_proc_buf == NULL)
+      ABORT("Insufficient space for /proc read");
 }
 
 # define READ read
@@ -4782,8 +4784,11 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES])
   /* addresses in FIND_LEAK output.                                     */
   void GC_print_address_map(void)
   {
+    char *maps;
+
     GC_err_printf("---------- Begin address map ----------\n");
-    GC_err_puts(GC_get_maps());
+    maps = GC_get_maps();
+    GC_err_puts(maps != NULL ? maps : "Failed to get map!\n");
     GC_err_printf("---------- End address map ----------\n");
   }
 #endif /* LINUX && ELF */