Commit d6d02774 authored by dearblue's avatar dearblue

Fix memory leak `sval` when out of memory in `Data_Wrap_Struct()`

parent b83e4df4
...@@ -39,10 +39,11 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass ...@@ -39,10 +39,11 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass
#define Data_Wrap_Struct(mrb,klass,type,ptr)\ #define Data_Wrap_Struct(mrb,klass,type,ptr)\
mrb_data_object_alloc(mrb,klass,ptr,type) mrb_data_object_alloc(mrb,klass,ptr,type)
#define Data_Make_Struct(mrb,klass,strct,type,sval,data) do { \ #define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \
(data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\
(sval) = mrb_malloc(mrb, sizeof(strct)); \ (sval) = mrb_malloc(mrb, sizeof(strct)); \
{ static const strct zero = { 0 }; *(sval) = zero; };\ { static const strct zero = { 0 }; *(sval) = zero; };\
(data) = Data_Wrap_Struct(mrb,klass,type,sval);\ (data_obj)->data = (sval);\
} while (0) } while (0)
#define RDATA(obj) ((struct RData *)(mrb_ptr(obj))) #define RDATA(obj) ((struct RData *)(mrb_ptr(obj)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment