From 050846ada9bc62a694c6ed80d40b17f74b342629 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 17 Apr 2025 17:04:20 -0700 Subject: [PATCH] lua memory allocated vs MONITOR_HEAP I hope this is temporary. nhrealloc() intends to deal with realloc(NULL, size) but something isn't working correctly. The code in alloc.c looks right so the problem might be in heaputil. However, the code there looks ok too. --- src/nhlua.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nhlua.c b/src/nhlua.c index ed9b3d877..bff707637 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 nhlua.c $NHDT-Date: 1711034373 2024/03/21 15:19:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.141 $ */ +/* NetHack 3.7 nhlua.c $NHDT-Date: 1744963460 2025/04/18 00:04:20 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.153 $ */ /* Copyright (c) 2018 by Pasi Kallinen */ /* NetHack may be freely redistributed. See license for details. */ @@ -2875,7 +2875,10 @@ nhl_alloc(void *ud, void *ptr, size_t osize UNUSED, size_t nsize) return NULL; } - return re_alloc(ptr, nsize); + /* realloc(NULL, size) is legitimate but confuses MONITOR_HEAP */ + if (!ptr) + return alloc((unsigned) nsize); + return re_alloc(ptr, (unsigned) nsize); } DISABLE_WARNING_UNREACHABLE_CODE