[Concept,13/37] malloc: Enable assertions if UNIT_TEST is enabled

Message ID 20251201170529.3237986-14-sjg@u-boot.org
State New
Headers
Series malloc: Import dlmalloc 2.8.6 |

Commit Message

Simon Glass Dec. 1, 2025, 5:04 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

dlmalloc has some sanity checks it performs on free() which can help
detect memory corruption. However, they are only enabled if DEBUG is
defined before including common.h. Define DEBUG earlier if UNIT_TEST is
enabled so that assertions are enabled in sandbox.

Changes from original commit(s):
- Combine commits 213adf6dffe and 1786861415f
- Use 'DEBUG 1' instead of 'DEBUG' since new dlmalloc uses '#if DEBUG'

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
(cherry picked from commit 6d7601e74437f3c915667a829ab722ba5174ec72)
(cherry picked from commit 1786861415f4494a38630584a8fbc9c939a024ce)
---

 common/dlmalloc.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Patch

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index f0b6db20f5c..98de6523758 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -544,6 +544,10 @@  MAX_RELEASE_CHECK_RATE   default: 4095 unless not HAVE_MMAP
 
 #ifdef __UBOOT__
 
+#if CONFIG_IS_ENABLED(UNIT_TEST)
+#define DEBUG 1
+#endif
+
 #define LACKS_FCNTL_H
 #define LACKS_UNISTD_H
 #define LACKS_SYS_PARAM_H