New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What happens to data_type after unhandled exception is being run? #3233
Comments
All |
@matz I was able to track down the problem: it arises when mruby calls Rust code that calls back mruby which causes an unhandled exception.
This breaks the first mruby context and interrupts the Rust code from finishing which should normally decrement a reference counter. Because the reference counter doesn't get decremented (it should get, even if mruby has an exception), this breaks the reference counter which will never call |
@matz Here's a minimal example: #include <stdlib.h>
#include <mruby.h>
#include <mruby/compile.h>
mrbc_context* ctx;
void c1(mrb_state* mrb) {
printf("entering c1\n");
mrb_load_nstring_cxt(mrb, "c2", 2, ctx);
printf("exiting c1\n");
}
void c2(mrb_state* mrb, mrb_value self) {
printf("entering c2\n");
void* p = malloc(10);
mrb_load_nstring_cxt(mrb, "raise 'hi'", 2, ctx);
free(p); // we're not freeing here
printf("exiting c2\n");
}
int main(void) {
mrb_state* mrb = mrb_open();
ctx = mrbc_context_new(mrb);
ctx->capture_errors = TRUE;
mrb_define_singleton_method(mrb, mrb->top_self, "c2", (mrb_func_t) c2, MRB_ARGS_NONE());
c1(mrb);
mrbc_context_free(mrb, ctx);
mrb_close(mrb);
return 0;
} The output is:
The issue is that |
@matz Any update on the issue? I still haven't figured out how to prevent the memory leak. |
You have to put those c methods in a try/catch block and manually free the just allocated memory. Take a look at https://github.com/mruby/mruby/tree/master/mrbgems/mruby-error |
@Asmod4n I'm trying to run
However, it does protect. |
I solved the issue by raising the caught exception within |
Does
free
get called onmrb_close
for all GC'd objects?I'm currently having an issue in mrusty where running into an unhandled exception leaks all the Rust objects that were lended to mruby because
free
doesn't seem to get called. There's a good chance that the bug might be in my code, but I haven't been able to figure it out so what I'm trying to ask is what is the best way to handle this use scenario?The text was updated successfully, but these errors were encountered: