From 2f4a49994a5207bdd5c9b426db011acf64ab25b4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 14 Mar 2021 18:29:00 +0200 Subject: [PATCH] builtin: implement support for `-d debug_malloc` too --- vlib/builtin/builtin.c.v | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vlib/builtin/builtin.c.v b/vlib/builtin/builtin.c.v index 30fb869f7d..6d61cedaf2 100644 --- a/vlib/builtin/builtin.c.v +++ b/vlib/builtin/builtin.c.v @@ -190,6 +190,11 @@ pub fn malloc(n int) byteptr { panic('malloc($n) failed') } } + $if debug_malloc ? { + // Fill in the memory with something != 0, so it is easier to spot + // when the calling code wrongly relies on it being zeroed. + C.memset(res, 0x88, n) + } return res } @@ -200,6 +205,7 @@ fn malloc_size(b byteptr) int // v_realloc resizes the memory block `b` with `n` bytes. // The `b byteptr` must be a pointer to an existing memory block // previously allocated with `malloc`, `v_calloc` or `vcalloc`. +// Please, see also realloc_data, and use it instead if possible. [unsafe] pub fn v_realloc(b byteptr, n int) byteptr { mut new_ptr := byteptr(0)