diff options
author | cooldome <cdome@bk.ru> | 2019-12-13 13:30:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-13 13:30:27 +0000 |
commit | 12d2b980e833c4747dea497add60f4e934cac512 (patch) | |
tree | f3a676bbc2752bfb65d08bdb96560c0b9fb025df /tests/destructor | |
parent | 777c9ad0ef47de8ff0f1c4387541c1d7b0a1fa6a (diff) | |
download | Nim-12d2b980e833c4747dea497add60f4e934cac512.tar.gz |
Fixes #12883 (#12894)
* fixes #12883 * fix comment * add normalize * fix
Diffstat (limited to 'tests/destructor')
-rw-r--r-- | tests/destructor/tdestructor3.nim | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/destructor/tdestructor3.nim b/tests/destructor/tdestructor3.nim index 4c251e0bf..b68aedce9 100644 --- a/tests/destructor/tdestructor3.nim +++ b/tests/destructor/tdestructor3.nim @@ -7,7 +7,13 @@ destroy destroy Foo: 123 destroy Foo: 5 (x1: (val: ...)) -destroy''' +destroy +--------------- +app begin +(val: ...) +destroy +app end +''' joinable: false """ @@ -93,3 +99,30 @@ proc test = echo obj2 test() + + +#------------------------------------------------------------ +# Issue #12883 + +type + TopObject = object + internal: UniquePtr[int] + +proc deleteTop(p: ptr TopObject) = + if p != nil: + `=destroy`(p[]) # !!! this operation used to leak the integer + deallocshared(p) + +proc createTop(): ptr TopObject = + result = cast[ptr TopObject](allocShared0(sizeof(TopObject))) + result.internal = newUniquePtr(1) + +proc test2() = + let x = createTop() + echo $x.internal + deleteTop(x) + +echo "---------------" +echo "app begin" +test2() +echo "app end" \ No newline at end of file |