diff options
author | Damien George <damien.p.george@gmail.com> | 2016-08-26 15:35:26 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-08-26 15:35:26 +1000 |
commit | 5ffe1d8dc07930818bbac6a88bec2aa5bd973402 (patch) | |
tree | 8832549d203085db88cb72d8abb6fea1c6d57d59 /py/malloc.c | |
parent | d29ca28288581ca788e468528ea1680b99eb49e5 (diff) |
py/gc: Add MICROPY_GC_CONSERVATIVE_CLEAR option to always zero memory.
There can be stray pointers in memory blocks that are not properly zero'd
after allocation. This patch adds a new config option to always zero all
allocated memory (via gc_alloc and gc_realloc) and hence help to eliminate
stray pointers.
See issue #2195.
Diffstat (limited to 'py/malloc.c')
-rw-r--r-- | py/malloc.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/py/malloc.c b/py/malloc.c index b0493d934..f48cb8da4 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -117,7 +117,10 @@ void *m_malloc0(size_t num_bytes) { if (ptr == NULL && num_bytes != 0) { return m_malloc_fail(num_bytes); } + // If this config is set then the GC clears all memory, so we don't need to. + #if !MICROPY_GC_CONSERVATIVE_CLEAR memset(ptr, 0, num_bytes); + #endif return ptr; } |