summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2015-05-29 17:12:52 +0200
committerFlorian Frank <flori@ping.de>2015-05-29 17:12:52 +0200
commitd4c99de78905d96c3f301f48b2c789943bb3f098 (patch)
tree82ddecaa902579a5f56b2c8f5d00e1399df5c5f3
parent638a1f782a5539281df39969d817cd7b55dd53f5 (diff)
parentfae344f2f12a73baf0d4afa663eee3d942aeec8e (diff)
downloadjson-d4c99de78905d96c3f301f48b2c789943bb3f098.tar.gz
Merge pull request #247 from nobu/potential_memory_leak
Potential memory leak
-rw-r--r--ext/json/ext/generator/generator.c11
-rw-r--r--ext/json/ext/generator/generator.h5
-rw-r--r--ext/json/ext/parser/parser.c14
-rw-r--r--ext/json/ext/parser/parser.h5
-rw-r--r--ext/json/ext/parser/parser.rl14
5 files changed, 15 insertions, 34 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index 90285be..6300c64 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/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/ext/generator/generator.h b/ext/json/ext/generator/generator.h
index 416159a..298c0a4 100644
--- a/ext/json/ext/generator/generator.h
+++ b/ext/json/ext/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
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index eed58e5..9c9d76a 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -2091,14 +2091,6 @@ static VALUE cParser_parse(VALUE self)
}
}
-
-static JSON_Parser *JSON_allocate(void)
-{
- JSON_Parser *json = ZALLOC(JSON_Parser);
- json->fbuffer = fbuffer_alloc(0);
- return json;
-}
-
static void JSON_mark(void *ptr)
{
JSON_Parser *json = ptr;
@@ -2135,8 +2127,10 @@ static const rb_data_type_t JSON_Parser_type = {
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
- JSON_Parser *json = JSON_allocate();
- return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
+ JSON_Parser *json;
+ VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
+ json->fbuffer = fbuffer_alloc(0);
+ return obj;
}
/*
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index e98f26a..abcc257 100644
--- a/ext/json/ext/parser/parser.h
+++ b/ext/json/ext/parser/parser.h
@@ -68,7 +68,6 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
static VALUE convert_encoding(VALUE source);
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
static VALUE cParser_parse(VALUE self);
-static JSON_Parser *JSON_allocate(void);
static void JSON_mark(void *json);
static void JSON_free(void *json);
static VALUE cJSON_parser_s_allocate(VALUE klass);
@@ -82,11 +81,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_Parser_type;
#define NEW_TYPEDDATA_WRAPPER 1
#else
-#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, JSON_mark, JSON_free, json)
+#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, JSON_free, json)
#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
#endif
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index b9b51aa..216ad26 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -814,14 +814,6 @@ static VALUE cParser_parse(VALUE self)
}
}
-
-static JSON_Parser *JSON_allocate(void)
-{
- JSON_Parser *json = ZALLOC(JSON_Parser);
- json->fbuffer = fbuffer_alloc(0);
- return json;
-}
-
static void JSON_mark(void *ptr)
{
JSON_Parser *json = ptr;
@@ -858,8 +850,10 @@ static const rb_data_type_t JSON_Parser_type = {
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
- JSON_Parser *json = JSON_allocate();
- return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
+ JSON_Parser *json;
+ VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
+ json->fbuffer = fbuffer_alloc(0);
+ return obj;
}
/*