From bb0f7049ce72a01c3def8ab674c199e2298029d8 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 10 Aug 2026 06:24:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(includes):=20MemBuddy=20chk=5Fstack=20?= =?UTF-8?q?=E6=BB=A1=E6=97=B6=20realloc=20=E7=BF=BB=E5=80=8D=E6=89=A9?= =?UTF-8?q?=E5=AE=B9=20-=20=E9=98=B2=2064K=20=E8=AE=B0=E5=BD=95=E6=A0=88?= =?UTF-8?q?=E7=88=86=E6=BB=A1=E5=AF=BC=E8=87=B4=20reset=20=E4=B8=8D?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E4=B8=8E=20=5Fis=5Fvalid=5Fptr=20=E6=A0=88?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=80=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/memhub.vp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/includes/memhub.vp b/includes/memhub.vp index 0db8107..8eabae5 100644 --- a/includes/memhub.vp +++ b/includes/memhub.vp @@ -537,9 +537,20 @@ class MemBuddy(MemManager): c.DerefAs(block, t.CVoid(t.CUInt64T((order << 1) | 1), t.CPtr)) result = t.CVoid(t.CUInt64T(block) + MEMBUDDY_HEADER_SIZE, t.CPtr) # 记录到 checkpoint 栈(供 reset_to 回收) - if self.chk_stack is not None and self.chk_depth < self.chk_cap: - self.chk_stack[self.chk_depth] = t.CUInt64T(block) - self.chk_depth += 1 + # 栈满时 stdlib.realloc 翻倍扩容(防 64K 爆满后记录缺失 + # → reset 不回收 + _is_valid_ptr 栈校验退化的连锁问题) + if self.chk_stack is not None: + if self.chk_depth >= self.chk_cap: + new_cap: t.CSizeT = self.chk_cap * 2 + new_stack: t.CVoid | t.CPtr = t.CVoid( + stdlib.realloc(self.chk_base, new_cap * 8), t.CPtr) + if new_stack is not None: + self.chk_base = new_stack + self.chk_stack = (t.CUInt64T | t.CPtr)(t.CVoid(new_stack, t.CPtr)) + self.chk_cap = new_cap + if self.chk_depth < self.chk_cap: + self.chk_stack[self.chk_depth] = t.CUInt64T(block) + self.chk_depth += 1 if result is None: # 分配失败(alloc(0) 或池耗尽):解锁并返回 None,由调用者决定后续处理。 # 不能 exit——测试依赖 alloc 失败返回 None 后继续 free+重试