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

ruby-changes:38577

From: nobu <ko1@a...>
Date: Thu, 28 May 2015 15:46:07 +0900 (JST)
Subject: [ruby-changes:38577] nobu:r50658 (trunk): tcltklib.c: allocate structs with wrapper

nobu	2015-05-28 15:45:55 +0900 (Thu, 28 May 2015)

  New Revision: 50658

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

  Log:
    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.

  Modified files:
    trunk/ext/tk/tcltklib.c
    trunk/ext/tk/tkutil/tkutil.c
Index: ext/tk/tcltklib.c
===================================================================
--- ext/tk/tcltklib.c	(revision 50657)
+++ ext/tk/tcltklib.c	(revision 50658)
@@ -6374,10 +6374,11 @@ ip_create_slave_core(interp, argc, argv) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6374
     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) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6417
     }
 #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) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6478
 
     rb_thread_critical = thr_crit_bup;
 
-    return TypedData_Wrap_Struct(CLASS_OF(interp), &tcltkip_type, slave);
+    return new_ip;
 }
 
 static VALUE
Index: ext/tk/tkutil/tkutil.c
===================================================================
--- ext/tk/tkutil/tkutil.c	(revision 50657)
+++ ext/tk/tkutil/tkutil.c	(revision 50658)
@@ -1199,7 +1199,8 @@ allocate_cbsubst_info(struct cbsubst_inf https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1199
   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_inf https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1219
 
   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) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1247
 
     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++]);

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

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