Cloptr and valgrind

hello,
I just wonder why I cannot free the memory from a linear closure in ATS2.
I try this :

#include “share/atspre_staload_tmpdef.hats”

staload UN = “prelude/SATS/unsafe.sats”

implement main0() = let
val cl = lam (x:int): int = x + 2
val r = cl 78
val () = cloptr_free($UN.castvwtp0{cloptr0}(cl))
in
println! ("res is : ", r)
end

compile it through : patscc -o test_cloptr -DATS_MEMALLOC_LIBC
test_cloptr.dats

and run it with valgrind :

@ valgrind ./test_cloptr
==16486== Memcheck, a memory error detector
==16486== Copyright © 2002-2012, and GNU GPL’d, by Julian Seward et al.
==16486== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==16486== Command: ./test_cloptr
==16486==
res is : 80
==16486==
==16486== HEAP SUMMARY:
==16486== in use at exit: 4,112 bytes in 3 blocks
==16486== total heap usage: 4 allocs, 1 frees, 4,120 bytes allocated
==16486==
==16486== LEAK SUMMARY:
==16486== definitely lost: 16 bytes in 2 blocks
==16486== indirectly lost: 0 bytes in 0 blocks
==16486== possibly lost: 0 bytes in 0 blocks
==16486== still reachable: 4,096 bytes in 1 blocks
==16486== suppressed: 0 bytes in 0 blocks
==16486== Rerun with --leak-check=full to see details of leaked memory
==16486==
==16486== For counts of detected and suppressed errors, rerun with: -v
==16486== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 18 from 3)

We can clearly see that memory is not released. Am I missing something ?
I did look in ATS1 and it works fine…

thanks :wink:

perfect !

@ valgrind ./test_cloptr
==22816== Memcheck, a memory error detector
==22816== Copyright © 2002-2012, and GNU GPL’d, by Julian Seward et al.
==22816== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==22816== Command: ./test_cloptr
==22816==
res is : 80
==22816==
==22816== HEAP SUMMARY:
==22816== in use at exit: 4,096 bytes in 1 blocks
==22816== total heap usage: 2 allocs, 1 frees, 4,104 bytes allocated
==22816==
==22816== LEAK SUMMARY:
==22816== definitely lost: 0 bytes in 0 blocks
==22816== indirectly lost: 0 bytes in 0 blocks
==22816== possibly lost: 0 bytes in 0 blocks
==22816== still reachable: 4,096 bytes in 1 blocks
==22816== suppressed: 0 bytes in 0 blocks
==22816== Rerun with --leak-check=full to see details of leaked memory
==22816==
==22816== For counts of detected and suppressed errors, rerun with: -v
==22816== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 18 from 3)

I fixed a bug last night, which could cause the above code to allocate two
(or more) closures.
If you git-pull the newest version of ATS2, then the problem should go
away. Please let me know if it
is the case. Thanks!