diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-28 07:17:55 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-28 07:17:55 +0000 |
commit | 2bb2310fe51e9ef9c09029a24e3f62f23e0db36a (patch) | |
tree | b30523e0cfc87534bbb6cd19e218e14fbf4e3611 /ext/json | |
parent | 60b0c53ea28606e2d0e2c7ab22978792a4f52189 (diff) | |
download | ruby-2bb2310fe51e9ef9c09029a24e3f62f23e0db36a.tar.gz |
generator.c: allocate structs with wrapper
* ext/json/generator/generator.c (cState_s_allocate): allocate
structs with making new wrapper objects and get rid of potential
memory leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json')
-rw-r--r-- | ext/json/generator/generator.c | 11 | ||||
-rw-r--r-- | ext/json/generator/generator.h | 5 |
2 files changed, 5 insertions, 11 deletions
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c index baf5360bb1..a135e28348 100644 --- a/ext/json/generator/generator.c +++ b/ext/json/generator/generator.c @@ -526,16 +526,11 @@ static const rb_data_type_t JSON_Generator_State_type = { }; #endif -static JSON_Generator_State *State_allocate(void) -{ - JSON_Generator_State *state = ZALLOC(JSON_Generator_State); - return state; -} - static VALUE cState_s_allocate(VALUE klass) { - JSON_Generator_State *state = State_allocate(); - return TypedData_Wrap_Struct(klass, &JSON_Generator_State_type, state); + JSON_Generator_State *state; + return TypedData_Make_Struct(klass, JSON_Generator_State, + &JSON_Generator_State_type, state); } /* diff --git a/ext/json/generator/generator.h b/ext/json/generator/generator.h index 416159a9c5..298c0a4965 100644 --- a/ext/json/generator/generator.h +++ b/ext/json/generator/generator.h @@ -112,7 +112,6 @@ static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self); static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self); static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self); static void State_free(void *state); -static JSON_Generator_State *State_allocate(void); static VALUE cState_s_allocate(VALUE klass); static VALUE cState_configure(VALUE self, VALUE opts); static VALUE cState_to_h(VALUE self); @@ -156,11 +155,11 @@ static inline void *ruby_zalloc(size_t n) return p; } #endif -#ifdef TypedData_Wrap_Struct +#ifdef TypedData_Make_Struct static const rb_data_type_t JSON_Generator_State_type; #define NEW_TYPEDDATA_WRAPPER 1 #else -#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json) +#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json) #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json) #endif |