summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2021-05-18 21:45:37 +0200
committerGitHub <noreply@github.com>2021-05-18 21:45:37 +0200
commit53935b8b27643215b677cc152f563a7fb7cb84fb (patch)
tree49ca8587fff40c58d6f094a3f1fc42e2e1d5d339 /lib
parent31143c68fc7438406df39207b30594e775b4f97e (diff)
downloadNim-53935b8b27643215b677cc152f563a7fb7cb84fb.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/system/seqs_v2.nim4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim
index b7f24ecd5..375eef340 100644
--- a/lib/system/seqs_v2.nim
+++ b/lib/system/seqs_v2.nim
@@ -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)