Hello,
I'm a little confused about memory management in Janet's C API. I'm trying to evaluate Janet expressions in a loop and print the results, but I'm running into issues with the string returned by janet_to_string().
Issue:
- If I call
janet_free(buff), the program crashes after the first iteration
- If I don't call
janet_free(buff), the program leaks memory on every iteration
#include "janet.h"
#include <stdio.h>
int main(int argc, const char *argv[]) {
janet_init();
JanetTable *env = janet_core_env(NULL);
Janet out;
while (1)
{
int status = janet_dostring(env, "(+ 1 1)", "main", &out);
char *buff = janet_to_string(out);
printf("result is %s\n", buff);
janet_free(buff); // <--- CRASHES HERE
}
janet_deinit();
return 0;
}
Hello,
I'm a little confused about memory management in Janet's C API. I'm trying to evaluate Janet expressions in a loop and print the results, but I'm running into issues with the string returned by
janet_to_string().Issue:
janet_free(buff), the program crashes after the first iterationjanet_free(buff), the program leaks memory on every iteration