When in sanity mode, un-zero malloc'd memory; fix uninitialized memory bugs.
authorEdward Z. Yang <ezyang@cs.stanford.edu>
Mon, 15 Aug 2016 09:22:28 +0000 (02:22 -0700)
committerEdward Z. Yang <ezyang@cs.stanford.edu>
Tue, 16 Aug 2016 01:05:46 +0000 (18:05 -0700)
malloc'd memory is not guaranteed to be zeroed.  On Linux, however,
it is often zeroed, leading to latent bugs.  In fact, with this
patch I fix two uninitialized memory bugs stemming from this.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate

Reviewers: simonmar, austin, Phyx, bgamari, erikd

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2455

rts/RtsUtils.c
rts/sm/Storage.c

index 716d203..3a97427 100644 (file)
@@ -79,6 +79,7 @@ stgMallocBytes (size_t n, char *msg)
       rtsConfig.mallocFailHook((W_) n, msg); /*msg*/
       stg_exit(EXIT_INTERNAL_ERROR);
     }
+    IF_DEBUG(sanity, memset(space, 0xbb, n));
     return space;
 }
 
index 3f88896..4d0c8d5 100644 (file)
@@ -106,6 +106,8 @@ initGeneration (generation *gen, int g)
     gen->n_scavenged_large_blocks = 0;
     gen->live_compact_objects = NULL;
     gen->n_live_compact_blocks = 0;
+    gen->compact_blocks_in_import = NULL;
+    gen->n_compact_blocks_in_import = 0;
     gen->mark = 0;
     gen->compact = 0;
     gen->bitmap = NULL;