summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
authordearblue <[email protected]>2019-06-02 10:43:54 +0900
committerdearblue <[email protected]>2019-06-05 23:19:16 +0900
commit97e999c409fbbe46fd4154e4be292f182f42b771 (patch)
tree8e3de3ca0e7613f350ded6486279f4ea591b0a53 /mrbgems
parent913a148ddc3fe1054ba99b59b0f12de114ee2de0 (diff)
downloadmruby-97e999c409fbbe46fd4154e4be292f182f42b771.tar.gz
mruby-97e999c409fbbe46fd4154e4be292f182f42b771.zip
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.
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/mruby-complex/src/complex.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index 5371332cd..a727eb604 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -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*