leakhunt/tools/probe_physobj_size.py
acbot 57b5e43d0e Initial commit — leak-hunt project complete
Five bugs identified and patched in retail Asheron's Call client:
- v3b: palette refcount over-increment (3-byte NOP at two sites)
- v5: RenderSurface PurgeResource no-op stub (vtable slot 2 thunk)
- v11: two dangling-pointer crash guards (NULL-check + reorder)
- v14: CEnvCell::Destroy ClipPlaneList leak (18-byte JMP to cleanup thunk)
- v22: unpacker stale-pointer SEH guard (whole-function __try/__except)

All five ship in leakfix.dll (117 KB, SHA d282f23c…) which is loaded
by acclient.exe at process start via PE import table patching by
tools/install_leakfix.py.

Controlled 15-client fleet soak: unpatched control died at 26h with
palette exhaustion; all 14 patched clients survived past that point
and reached ≥5-day uptime.

Residual ~15 MB/h growth traced to d3d9.dll's internal slab allocator
(260KB surface backing buffers retained after Release). See REPORT.md
§10 for the full investigation; conclusion is that it's unfixable from
outside d3d9.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 21:07:58 +02:00

50 lines
1.3 KiB
Python

"""probe_physobj_size.py <dump.dmp>
Find density/spacing of CPhysicsObj instances in the dump.
Spec says 90 leaked + many live ones in CObjectMaint's hash.
"""
import struct, sys
from minidump.minidumpfile import MinidumpFile
from collections import Counter
PHYS_VT = 0x007c78ec
def _ei(v):
if v is None: return 0
if hasattr(v, 'value'): return int(v.value)
return int(v)
md = MinidumpFile.parse(sys.argv[1])
reader = md.get_reader().get_buffered_reader()
scan = []
for r in md.memory_info.infos:
st, ty, pr = _ei(r.State), _ei(r.Type), _ei(r.Protect) & 0xff
if st != 0x1000 or ty == 0x1000000 or pr not in (0x04, 0x40): continue
scan.append((r.BaseAddress, r.RegionSize))
addrs = []
for base, size in scan:
try:
reader.move(base); buf = reader.read(size)
except Exception:
continue
if not buf: continue
end = (len(buf) // 4) * 4
for off in range(0, end - 4, 4):
if struct.unpack_from("<I", buf, off)[0] == PHYS_VT:
addrs.append(base + off)
addrs.sort()
print(f"CPhysicsObj instances by vtable signature: {len(addrs)}")
deltas = Counter()
for i in range(1, len(addrs)):
d = addrs[i] - addrs[i-1]
if d < 0x8000:
deltas[d] += 1
print("top inter-instance deltas:")
for d, n in deltas.most_common(15):
print(f" 0x{d:04x} ({d:>6}) x{n}")