Commit Graph

10 Commits

Author SHA1 Message Date
KBS
e62ed261c5 base/runtime: do not free the original block on a failed heap resize
`base/runtime`: do not free the original block on a failed heap resize

The default heap allocator freed old_ptr when the underlying allocation
failed (allocated_mem == nil). On the realloc path (heap_resize) the original
block is left intact on failure, and on the copy/fresh path old_ptr has not
been copied or freed yet, so freeing it left the caller holding a dangling
pointer. A [dynamic] array whose resize failed therefore double-freed its
data on the next delete (reported as free(): invalid pointer / use-after-free).

Return .Out_Of_Memory without freeing anything; the caller retains ownership
of the original block.

Fixes #7262
2026-08-16 12:54:16 +02:00
gingerBill
ac01d1b5bf Add runtime.conditional_mem_zero to improve heap_allocator performance on non-Windows systems 2025-09-27 09:58:28 +01:00
Damian Tarnawski
21fd7c200e Add require_results attr to procs returning an allocator 2025-09-02 13:03:15 +02:00
flysand7
bec09d82df Fix vet errors 2024-09-19 21:07:08 +11:00
flysand7
e0bb07728d Fix resize OOB when copying old data that's bigger than new data 2024-09-19 20:55:52 +11:00
gingerBill
bed18a17e6 Bodge: Improve aligned_resize logic 2024-08-06 11:22:34 +01:00
gingerBill
93441a043a Make runtime.heap_alloc contextless 2024-06-25 09:38:49 +01:00
gingerBill
0428f508d8 Fix typo of _heap_resize 2024-01-28 23:21:59 +00:00
gingerBill
038086d1d9 Alias heap calls from base:runtime is core:os 2024-01-28 22:47:55 +00:00
gingerBill
9a16bc5fc5 Remove core:os dependency for base:runtime 2024-01-28 22:40:46 +00:00