summaryrefslogtreecommitdiff
path: root/ext/json/ext/parser/parser.rl
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 07:17:42 +0000
committerNobuyoshi Nakada <nobu@ruby-lang.org>2015-05-28 16:19:43 +0900
commit6020ec8585cb0ee9d5b0166b27fa53ca1170653e (patch)
tree7725f0b50f536ac40cf05d70b481df8cb10ab20d /ext/json/ext/parser/parser.rl
parent638a1f782a5539281df39969d817cd7b55dd53f5 (diff)
downloadjson-6020ec8585cb0ee9d5b0166b27fa53ca1170653e.tar.gz
parser.rl: allocate structs with wrapper
* ext/json/ext/parser/parser.rl (cJSON_parser_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@50660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/ext/parser/parser.rl')
-rw-r--r--ext/json/ext/parser/parser.rl14
1 files changed, 4 insertions, 10 deletions
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;
}
/*