ARC: fixes memory leaks with newSeq used in a loop [backport:1.4] (#18040)

* ARC: fixes memory leaks with newSeq used in a loop [backport:1.4]
* Update tests/arc/tnewseq_legacy.nim
This commit is contained in:
Andreas Rumpf 2021-05-18 21:45:37 +02:00 • committed by GitHub
commit 53935b8b27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -124,3 +124,7 @@ proc setLen[T](s: var seq[T], newlen: Natural) =
if xu.p == nil or xu.p.cap < newlen:
xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newlen - oldLen, sizeof(T), alignof(T)))
xu.len = newlen
proc newSeq[T](s: var seq[T], len: Natural) =
shrink(s, 0)
setLen(s, len)