Skip to content

Commit 70ed2d0

Browse files
Fix GC.malloc for gc_none to clear memory (#14746)
`GC.malloc` is supposed to clear the memory, but libc `malloc` does not do this. So we need to add it explicitly.
1 parent 5cf6df9 commit 70ed2d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/gc/none.cr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ module GC
1010
# :nodoc:
1111
def self.malloc(size : LibC::SizeT) : Void*
1212
Crystal.trace :gc, "malloc", size: size
13-
LibC.malloc(size)
13+
# libc malloc is not guaranteed to return cleared memory, so we need to
14+
# explicitly clear it. Ref: https://github.com/crystal-lang/crystal/issues/14678
15+
LibC.malloc(size).tap(&.clear)
1416
end
1517

1618
# :nodoc:

0 commit comments

Comments
 (0)