I'm writing an interface to a C library. A C function allocates some memory, reads a value, and returns a void *
pointer to that buffer, to be subsequently freed.
I wish to be sure that when I assign the output of a call to nativecast(Str, $data)
to a Raku Str variable, the data is assigned to the variable (copied into), not just bound to it, so I can free the space allocated by the C function soon after the assignment.
This is approximately what the code looks like:
my Pointer $data = c_read($source);
my Str $value = nativecast(Str, $data);
c_free($data);
# $value is now ready to be used
I run this code through valgrind, which didn't report any attempt to reference a freed memory buffer. Still I'm curious.