diff options
author | alaviss <leorize+oss@disroot.org> | 2020-08-17 18:20:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 20:20:48 +0200 |
commit | e9df8ebcfd475a715756d24e1718a5c1455689d2 (patch) | |
tree | 06380aad49cddd8151f5a28dad8bbf6ca03ead3a /lib/system | |
parent | 6feb3900b121a356a1c091855008d080223ea802 (diff) | |
download | Nim-e9df8ebcfd475a715756d24e1718a5c1455689d2.tar.gz |
gc_regions: cleanup & fixes for deallocation (#11920)
* gc_regions: withRegion nows return the modified MemRegion * gc_regions: make withScratchRegion dealloc correctly * tests/gc: add tregionleak test This test checks if memory within regions are freed properly.
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/gc_regions.nim | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/system/gc_regions.nim b/lib/system/gc_regions.nim index 4f802c812..9425e040a 100644 --- a/lib/system/gc_regions.nim +++ b/lib/system/gc_regions.nim @@ -87,13 +87,13 @@ var tlRegion {.threadVar.}: MemRegion # tempStrRegion {.threadVar.}: MemRegion # not yet used -template withRegion*(r: MemRegion; body: untyped) = +template withRegion*(r: var MemRegion; body: untyped) = let oldRegion = tlRegion tlRegion = r try: body finally: - #r = tlRegion + r = tlRegion tlRegion = oldRegion template inc(p: pointer, s: int) = @@ -262,14 +262,13 @@ when false: setObstackPtr(obs) template withScratchRegion*(body: untyped) = - var scratch: MemRegion let oldRegion = tlRegion - tlRegion = scratch + tlRegion = MemRegion() try: body finally: + deallocAll() tlRegion = oldRegion - deallocAll(scratch) when false: proc joinRegion*(dest: var MemRegion; src: MemRegion) = |