summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 06:45:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 06:45:55 +0000
commitfbc67dbf2c73954607e22dc9079ddfc0b2a3c233 (patch)
tree2e20290762add273874cf62b61a0c7c2adfd5d45 /ext
parentd50260117f4743eaf87fbb553eee7c48d74bc6b2 (diff)
tcltklib.c: allocate structs with wrapper
* ext/tk/tcltklib.c (ip_create_slave_core): allocate structs with making new wrapper objects and get rid of potential memory leak. * ext/tk/tkutil/tkutil.c (allocate_cbsubst_info): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/tk/tcltklib.c7
-rw-r--r--ext/tk/tkutil/tkutil.c7
2 files changed, 9 insertions, 5 deletions
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c
index 40d546ea9d..f082d3922f 100644
--- a/ext/tk/tcltklib.c
+++ b/ext/tk/tcltklib.c
@@ -6374,10 +6374,11 @@ ip_create_slave_core(interp, argc, argv)
VALUE *argv;
{
struct tcltkip *master = get_ip(interp);
- struct tcltkip *slave = ALLOC(struct tcltkip);
+ struct tcltkip *slave;
/* struct tcltkip *slave = RbTk_ALLOC_N(struct tcltkip, 1); */
VALUE safemode;
VALUE name;
+ VALUE new_ip;
int safe;
int thr_crit_bup;
Tk_Window mainWin;
@@ -6416,6 +6417,8 @@ ip_create_slave_core(interp, argc, argv)
}
#endif
+ new_ip = TypedData_Make_Struct(CLASS_OF(interp), struct tcltkip,
+ &tcltkip_type, slave);
/* create slave-ip */
#ifdef RUBY_USE_NATIVE_THREAD
/* slave->tk_thread_id = 0; */
@@ -6475,7 +6478,7 @@ ip_create_slave_core(interp, argc, argv)
rb_thread_critical = thr_crit_bup;
- return TypedData_Wrap_Struct(CLASS_OF(interp), &tcltkip_type, slave);
+ return new_ip;
}
static VALUE
diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c
index 6035a2a613..e0b8581759 100644
--- a/ext/tk/tkutil/tkutil.c
+++ b/ext/tk/tkutil/tkutil.c
@@ -1199,7 +1199,8 @@ allocate_cbsubst_info(struct cbsubst_info **inf_ptr)
volatile VALUE proc, aliases;
int idx;
- inf = ALLOC(struct cbsubst_info);
+ VALUE info = TypedData_Make_Struct(cSUBST_INFO, struct cbsubst_info,
+ &cbsubst_info_type, inf);
inf->full_subst_length = 0;
@@ -1218,7 +1219,7 @@ allocate_cbsubst_info(struct cbsubst_info **inf_ptr)
if (inf_ptr != (struct cbsubst_info **)NULL) *inf_ptr = inf;
- return TypedData_Wrap_Struct(cSUBST_INFO, &cbsubst_info_type, inf);
+ return info;
}
static void
@@ -1246,7 +1247,7 @@ cbsubst_initialize(argc, argv, self)
inf = cbsubst_get_ptr(rb_obj_class(self));
- idx = 0;
+ idx = 0;
for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) {
if ( inf->ivar[iv_idx] == (ID) 0 ) continue;
rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]);