[前][次][番号順一覧][スレッド一覧]

ruby-changes:38591

From: nobu <ko1@a...>
Date: Fri, 29 May 2015 14:44:14 +0900 (JST)
Subject: [ruby-changes:38591] nobu:r50672 (trunk): psych: allocate structs with wrapper

nobu	2015-05-29 14:44:01 +0900 (Fri, 29 May 2015)

  New Revision: 50672

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50672

  Log:
    psych: allocate structs with wrapper
    
    * ext/psych/psych_emitter.c (allocate): allocate structs with
      making new wrapper objects and get rid of potential memory leak.
    
    * ext/psych/psych_parser.c (allocate): ditto.

  Modified files:
    trunk/ext/psych/psych_emitter.c
    trunk/ext/psych/psych_parser.c
Index: ext/psych/psych_parser.c
===================================================================
--- ext/psych/psych_parser.c	(revision 50671)
+++ ext/psych/psych_parser.c	(revision 50672)
@@ -70,11 +70,11 @@ static const rb_data_type_t psych_parser https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L70
 static VALUE allocate(VALUE klass)
 {
     yaml_parser_t * parser;
+    VALUE obj = TypedData_Make_Struct(klass, yaml_parser_t, &psych_parser_type, parser);
 
-    parser = xmalloc(sizeof(yaml_parser_t));
     yaml_parser_initialize(parser);
 
-    return TypedData_Wrap_Struct(klass, &psych_parser_type, parser);
+    return obj;
 }
 
 static VALUE make_exception(yaml_parser_t * parser, VALUE path)
Index: ext/psych/psych_emitter.c
===================================================================
--- ext/psych/psych_emitter.c	(revision 50671)
+++ ext/psych/psych_emitter.c	(revision 50672)
@@ -50,14 +50,13 @@ static const rb_data_type_t psych_emitte https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L50
 static VALUE allocate(VALUE klass)
 {
     yaml_emitter_t * emitter;
-
-    emitter = xmalloc(sizeof(yaml_emitter_t));
+    VALUE obj = TypedData_Make_Struct(klass, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_emitter_initialize(emitter);
     yaml_emitter_set_unicode(emitter, 1);
     yaml_emitter_set_indent(emitter, 2);
 
-    return TypedData_Wrap_Struct(klass, &psych_emitter_type, emitter);
+    return obj;
 }
 
 /* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]