[gambit-list] Memory leak (?) using `c-define`d functions from foreign release functions.

Estevo euccastro at gmail.com
Thu Dec 26 17:23:01 EST 2013

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

; ~/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);
    return ___FIX(___NO_ERR);


(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 =

(println "p is " p)
(set! p #f)

; for good measure...

(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
p is #<point* #2 0x5c04640>
release-point called
==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
==16301== 71 bytes in 1 blocks are definitely lost in loss record 1 of 1
==16301==    at 0x4C2B6CD: malloc (in
==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== 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== For counts of detected and suppressed errors, rerun with: -v
==16301== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20131226/c7ae2ca8/attachment.htm>

More information about the Gambit-list mailing list