develooper Front page | perl.perl6.users | Postings from January 2018

Memory leak with NativeCall

Thread Next
David E.
January 22, 2018 00:25
Memory leak with NativeCall
Message ID:
I'm not certain where to report this (ie: rakudo vs MoarVM), so I'm
starting here.

After some experimentation, I finally traced down a segfault I've been
getting to a memory leak in the NativeCall interface.  I'm using it to
facilitate testing of a 32-bit embedded (meaning no dynamic allocation) C
library in an easier/more-comprehensive way than I could otherwise --
though this memory leak is preventing me from running the long-duration
tests that I need to.

I'm currently running 2017.12.1
(commit c84ed2942d224e4cd524fa389e0603e4e4642f77) under a 32-bit Docker
Ubuntu image (I started with 2017.10).  I can easily observe the memory
leak using "docker stats".  At it's worst, with my full application, I'm
seeing approximately 0.01 GiB of memory per second getting lost.

Below is sample code that is able to reproduce the leak.  I believe that it
has something to do with the callback, maybe with the C-string conversion.

Please advise,


use v6;
use NativeCall;

constant LIB_DTEST = '';

sub dtest_log_init(&dt_csv_log (Str)) is native(LIB_DTEST) {*};
sub test_cb() is native(LIB_DTEST) {*};

sub dt_csv_log(Str $data)
    prompt "dt_csv_log($data)";

sub MAIN()

    while 1 {
        # prompt "Call test_cb()";


#include <stdio.h>
void (*dtlf)(char* s);
void dtest_log_init(void (*fp)(char* s))
  printf("Assigning dtlf to fp=0x%x\n", (int)fp);
   dtlf = fp;
void test_cb(void)

The following is a snippet from my Dockerfile that installed perl6:

    && git clone /root/rakudo \
    && echo 'export
>> ~/.bashrc \
    && cd ~/rakudo && git checkout master && git pull \
    && git checkout $(git describe --abbrev=0 --tags) \
    && perl --gen-moar --gen-nqp --backends=moar \
    && make && make install \

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About