hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 7bc46f6099382a5ca3f2323d1611ffe8c9a90998
parent d0f79b741d712c151d2d0e1496b17b692656cb04
Author: Alexey Yerin <yyp@disroot.org>
Date:   Sat, 19 Aug 2023 12:15:33 +0300

rt+libc: free() the pointer in realloc(p, 0)

This copies the interface of non-libc malloc and prevents valgrind from
reporting "realloc() with size 0" when slices are freed in rt::unensure.

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mrt/malloc+libc.ha | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/rt/malloc+libc.ha b/rt/malloc+libc.ha @@ -14,6 +14,10 @@ export fn malloc(n: size) nullable *void = { // in-place. Returns null if there is insufficient memory to support the // request. export fn realloc(p: nullable *void, n: size) nullable *void = { + if (n == 0) { + free(p); + return null; + }; return c_realloc(p, n); };