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.
This commit is contained in:
Damien George
2016-08-26 15:35:26 +10:00
parent d29ca28288
commit 5ffe1d8dc0
3 changed files with 22 additions and 0 deletions

View File

@@ -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;
}