Skip to content

Commit fae344f

Browse files
committed
generator.c: allocate structs with wrapper
* ext/json/ext/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
1 parent 6020ec8 commit fae344f

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

ext/json/ext/generator/generator.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,11 @@ static const rb_data_type_t JSON_Generator_State_type = {
526526
};
527527
#endif
528528

529-
static JSON_Generator_State *State_allocate(void)
530-
{
531-
JSON_Generator_State *state = ZALLOC(JSON_Generator_State);
532-
return state;
533-
}
534-
535529
static VALUE cState_s_allocate(VALUE klass)
536530
{
537-
JSON_Generator_State *state = State_allocate();
538-
return TypedData_Wrap_Struct(klass, &JSON_Generator_State_type, state);
531+
JSON_Generator_State *state;
532+
return TypedData_Make_Struct(klass, JSON_Generator_State,
533+
&JSON_Generator_State_type, state);
539534
}
540535

541536
/*

ext/json/ext/generator/generator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
112112
static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
113113
static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
114114
static void State_free(void *state);
115-
static JSON_Generator_State *State_allocate(void);
116115
static VALUE cState_s_allocate(VALUE klass);
117116
static VALUE cState_configure(VALUE self, VALUE opts);
118117
static VALUE cState_to_h(VALUE self);
@@ -156,11 +155,11 @@ static inline void *ruby_zalloc(size_t n)
156155
return p;
157156
}
158157
#endif
159-
#ifdef TypedData_Wrap_Struct
158+
#ifdef TypedData_Make_Struct
160159
static const rb_data_type_t JSON_Generator_State_type;
161160
#define NEW_TYPEDDATA_WRAPPER 1
162161
#else
163-
#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json)
162+
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
164163
#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
165164
#endif
166165

0 commit comments

Comments
 (0)