diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-27 08:02:28 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-27 08:02:28 +0000 |
commit | d0fb46b096e8268b97b949d0c9c6642738e6174f (patch) | |
tree | 070f03193ada1f335cd8bc5870a929aa9f5242a3 /ext/bigdecimal | |
parent | df5c989ae93b85663075a1c696d98979908dd998 (diff) | |
download | ruby-d0fb46b096e8268b97b949d0c9c6642738e6174f.tar.gz |
bigdecimal.c: wrapper object before alloc
* ext/bigdecimal/bigdecimal.c (VpNewRbClass): make wrapper object
before result structs allocation and manage refcount for each
elements to get rid of potential memory leak.
* ext/bigdecimal/bigdecimal.c (BigDecimal_global_new): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index ce06e65e3f..7d498724fe 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -598,17 +598,17 @@ GetPositiveInt(VALUE v) VP_EXPORT Real * VpNewRbClass(size_t mx, const char *str, VALUE klass) { + VALUE obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, 0); Real *pv = VpAlloc(mx,str); - pv->obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, pv); + RTYPEDDATA_DATA(obj) = pv; + pv->obj = obj; return pv; } VP_EXPORT Real * VpCreateRbObject(size_t mx, const char *str) { - Real *pv = VpAlloc(mx,str); - pv->obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, pv); - return pv; + return VpNewRbClass(mx, str, rb_cBigDecimal); } #define VpAllocReal(prec) (Real *)VpMemAlloc(offsetof(Real, frac) + (prec) * sizeof(BDIGIT)) @@ -2595,11 +2595,13 @@ BigDecimal_global_new(int argc, VALUE *argv, VALUE self) { ENTER(1); Real *pv; + VALUE obj; + obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0); GUARD_OBJ(pv, BigDecimal_new(argc, argv)); if (ToValue(pv)) pv = VpCopy(NULL, pv); - pv->obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, pv); - return pv->obj; + RTYPEDDATA_DATA(obj) = pv; + return pv->obj = obj; } /* call-seq: |