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.
diff --git a/py/malloc.c b/py/malloc.c
index b0493d9..f48cb8d 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -117,7 +117,10 @@
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;
}