Fix memory leak in Complex method by RData

If `Data_Wrap_Struct()` raises a `NoMemoryError` exception,
it will leak memory if it does `mrb_malloc()` first.
This commit is contained in:
dearblue
2019-06-02 10:43:54 +09:00
parent 913a148ddc
commit 97e999c409
+3 -2
View File
@@ -40,12 +40,13 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
{
struct RClass *c = mrb_class_get(mrb, "Complex");
struct mrb_complex *p;
struct RData *d;
p = (struct mrb_complex*)mrb_malloc(mrb, sizeof(struct mrb_complex));
Data_Make_Struct(mrb, c, struct mrb_complex, &mrb_complex_type, p, d);
p->real = real;
p->imaginary = imaginary;
return mrb_obj_value(Data_Wrap_Struct(mrb, c, &mrb_complex_type, p));
return mrb_obj_value(d);
}
static struct mrb_complex*