crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.21k stars 1.61k forks source link

`GC.malloc` doesn't clear memory (as specified) for `gc_none` #14678

Closed BlobCodes closed 2 days ago

BlobCodes commented 3 weeks ago

Bug Report

The method GC#malloc is described as follows:

# Allocates and clears *size* bytes of memory.
#
# The resulting object may contain pointers and they will be tracked by the GC.
#
# The memory will be automatically deallocated when unreferenced.

However, the gc_none implementation simply delegates this method to LibC.malloc - which doesn't clear the memory.

To fix this, either an explicit clear could be added, or the malloc could be replaced by a calloc.