mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
238394e738
commit
5924f9a684
2 changed files with 4 additions and 5 deletions
|
@ -50,14 +50,13 @@ static const rb_data_type_t psych_emitter_type = {
|
|||
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)
|
||||
|
|
|
@ -70,11 +70,11 @@ static const rb_data_type_t psych_parser_type = {
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue