Valgrind reports Gambit is leaking a "sfun stack marker" if I call, from a foreign release function, another function defined with `c-define`. The code below is
about the most innocent looking thing I could come up with.
Doesn't Gambit like c-define functions called within release
functions, or is Valgrind giving me a false positive here (as it is wont to do quite often.)
; ~/gambit-dbg/bin/gsc -exe -cc-options -g test-c-define.scm && valgrind --leak-check=full ./test-c-define
(c-declare #<<c-declare-end
typedef struct { int x; int y; } point;
void scm_release_point(unsigned long);
___SCMOBJ c_release_point(void *ptr) {
scm_release_point((unsigned long)ptr);
___EXT(___release_rc)(ptr);
return ___FIX(___NO_ERR);
}
c-declare-end
)
(c-define (release-point ptr) (unsigned-long) void "scm_release_point" ""
(println "release-point called"))
(c-define-type point (pointer "point" (point*) "c_release_point"))
(define p ((c-lambda () point
"___result_voidstar = ___EXT(___alloc_rc)(sizeof(point));")))
(println "p is " p)
(set! p #f)
(##gc)
; for good measure...
(##gc)
(##gc)
(println "Bye.")
valgrind --leak-check=full ./test-c-define
==16301== Memcheck, a memory error detector
==16301== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==16301== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==16301== Command: ./test-c-define
==16301==
p is #<point* #2 0x5c04640>
release-point called
Bye.
==16301==
==16301== HEAP SUMMARY:
==16301== in use at exit: 71 bytes in 1 blocks
==16301== total heap usage: 153 allocs, 152 frees, 4,247,198 bytes allocated
==16301==
==16301== 71 bytes in 1 blocks are definitely lost in loss record 1 of 1
==16301== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16301== by 0x4C922E: ___alloc_mem (os_base.c:185)
==16301== by 0x4B7DB5: alloc_mem_aligned (mem.c:452)
==16301== by 0x4B8C57: alloc_scmobj_still (mem.c:1245)
==16301== by 0x4B8D61: ___alloc_scmobj (mem.c:1285)
==16301== by 0x4B8E44: ___make_vector (mem.c:1362)
==16301== by 0x4C677B: ___make_sfun_stack_marker (c_intf.c:6452)
==16301== by 0x4B359E: scm_release_point (test-c-define.c:139)
==16301== by 0x4B354B: c_release_point (test-c-define.c:130)
==16301== by 0x4C24D7: ___release_foreign (c_intf.c:1713)
==16301== by 0x4BC354: free_unmarked_still_objs (mem.c:3271)
==16301== by 0x4BE922: ___garbage_collect (mem.c:4698)
==16301==
==16301== LEAK SUMMARY:
==16301== definitely lost: 71 bytes in 1 blocks
==16301== indirectly lost: 0 bytes in 0 blocks
==16301== possibly lost: 0 bytes in 0 blocks
==16301== still reachable: 0 bytes in 0 blocks
==16301== suppressed: 0 bytes in 0 blocks
==16301==
==16301== For counts of detected and suppressed errors, rerun with: -v
==16301== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)