Fix NULL pointer dereference with mruby-os-memsize and mruby-method

If it gets an insubstantial method object with `obj.method`, it will raise a `SIGSEGV` with `ObjectSpace.memsize_of(method)`.
This commit is contained in:
dearblue
2021-01-16 15:52:52 +09:00
parent 0aa8db9a06
commit 0fdf5d9bb9
+1
View File
@@ -33,6 +33,7 @@ os_memsize_of_method(mrb_state* mrb, mrb_value method_obj)
size_t size;
mrb_value proc_value = mrb_obj_iv_get(mrb, mrb_obj_ptr(method_obj),
mrb_intern_lit(mrb, "_proc"));
if (mrb_nil_p(proc_value)) return 0;
struct RProc *proc = mrb_proc_ptr(proc_value);
size = sizeof(struct RProc);