From 5f603144b2f0050e44b5e24a21772647f6112536 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sun, 21 Jan 2018 20:59:25 +0100 Subject: [PATCH] GC: fixes size computation for leak detection --- lib/system/gc_common.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/system/gc_common.nim b/lib/system/gc_common.nim index d117c17da..093a379a5 100644 --- a/lib/system/gc_common.nim +++ b/lib/system/gc_common.nim @@ -47,7 +47,7 @@ when defined(nimTypeNames): var n = 0 var it = nimTypeRoot while it != nil: - if it.instances > 0 and n < a.len: + if (it.instances > 0 or it.sizes != 0) and n < a.len: a[n] = (it.name, it.instances, it.sizes) inc n it = it.nextType @@ -67,9 +67,9 @@ template decTypeSize(cell, t) = # XXX this needs to use atomics for multithreaded apps! when defined(nimTypeNames): if t.kind in {tyString, tySequence}: - let len = cast[PGenericSeq](cellToUsr(cell)).len - let base = if t.kind == tyString: 1 else: t.base.size - let size = addInt(mulInt(len, base), GenericSeqSize) + let cap = cast[PGenericSeq](cellToUsr(cell)).space + let size = if t.kind == tyString: cap+1+GenericSeqSize + else: addInt(mulInt(cap, t.base.size), GenericSeqSize) dec t.sizes, size+sizeof(Cell) else: dec t.sizes, t.base.size+sizeof(Cell)