kopia lustrzana https://github.com/micropython/micropython
Revert "py/gc: Zero out all newly allocated memory to prevent stale pointers."
This reverts commit 1c0343f9d9
.
Reason: to make merging simpler. This feature will anyway be provided by
master in a later version.
pull/9172/head
rodzic
e52758da22
commit
b4078cbbf3
8
py/gc.c
8
py/gc.c
|
@ -409,12 +409,12 @@ found:
|
|||
void *ret_ptr = (void*)(MP_STATE_MEM(gc_pool_start) + start_block * BYTES_PER_BLOCK);
|
||||
DEBUG_printf("gc_alloc(%p)\n", ret_ptr);
|
||||
|
||||
// Zero out all the bytes of the newly allocated blocks.
|
||||
// zero out the additional bytes of the newly allocated blocks
|
||||
// This is needed because the blocks may have previously held pointers
|
||||
// to the heap and will not be set to something else if the caller
|
||||
// doesn't actually use the entire block. As such they will continue
|
||||
// to point to the heap and may prevent other blocks from being reclaimed.
|
||||
memset((byte*)ret_ptr, 0, (end_block - start_block + 1) * BYTES_PER_BLOCK);
|
||||
memset((byte*)ret_ptr + n_bytes, 0, (end_block - start_block + 1) * BYTES_PER_BLOCK - n_bytes);
|
||||
|
||||
#if MICROPY_ENABLE_FINALISER
|
||||
if (has_finaliser) {
|
||||
|
@ -620,8 +620,8 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
|
|||
ATB_FREE_TO_TAIL(bl);
|
||||
}
|
||||
|
||||
// zero out the bytes of the newly allocated blocks (see comment above in gc_alloc)
|
||||
memset((byte*)ptr_in + n_blocks * BYTES_PER_BLOCK, 0, (new_blocks - n_blocks) * BYTES_PER_BLOCK);
|
||||
// zero out the additional bytes of the newly allocated blocks (see comment above in gc_alloc)
|
||||
memset((byte*)ptr_in + n_bytes, 0, new_blocks * BYTES_PER_BLOCK - n_bytes);
|
||||
|
||||
#if EXTENSIVE_HEAP_PROFILING
|
||||
gc_dump_alloc_table();
|
||||
|
|
|
@ -114,7 +114,10 @@ void *m_malloc_with_finaliser(size_t num_bytes) {
|
|||
|
||||
void *m_malloc0(size_t num_bytes) {
|
||||
void *ptr = m_malloc(num_bytes);
|
||||
// memory is already cleared by gc_alloc
|
||||
if (ptr == NULL && num_bytes != 0) {
|
||||
return m_malloc_fail(num_bytes);
|
||||
}
|
||||
memset(ptr, 0, num_bytes);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue