From 6fb9349d85960858023eb9c16826b68408279175 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 16 May 2015 12:56:48 +0000 Subject: allocate structs with wrapper * parse.y (rb_parser_new, ripper_s_allocate): allocate structs with making new wrapper objects and get rid of potential memory leak. * variable.c (rb_autoload): ditto. * ext/digest/digest.c (rb_digest_base_alloc): ditto. * ext/strscan/strscan.c (strscan_s_allocate): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/digest/digest.c | 5 ++--- ext/strscan/strscan.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'ext') diff --git a/ext/digest/digest.c b/ext/digest/digest.c index ed96c2f274..239fe7cb10 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -565,11 +565,10 @@ rb_digest_base_alloc(VALUE klass) algo = get_digest_base_metadata(klass); - pctx = xmalloc(algo->ctx_size); + obj = rb_data_typed_object_zalloc(klass, algo->ctx_size, &digest_type); + pctx = RTYPEDDATA_DATA(obj); algo_init(algo, pctx); - obj = TypedData_Wrap_Struct(klass, &digest_type, pctx); - return obj; } diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c index 55d13d413b..a0a015bed5 100644 --- a/ext/strscan/strscan.c +++ b/ext/strscan/strscan.c @@ -198,12 +198,12 @@ static VALUE strscan_s_allocate(VALUE klass) { struct strscanner *p; + VALUE obj = TypedData_Make_Struct(klass, struct strscanner, &strscanner_type, p); - p = ZALLOC(struct strscanner); CLEAR_MATCH_STATUS(p); onig_region_init(&(p->regs)); p->str = Qnil; - return TypedData_Wrap_Struct(klass, &strscanner_type, p); + return obj; } /* -- cgit v1.2.3