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

ruby-changes:13962

From: mame <ko1@a...>
Date: Sat, 14 Nov 2009 21:56:34 +0900 (JST)
Subject: [ruby-changes:13962] Ruby:r25768 (trunk): * class.c (rb_mod_init_copy): fix memory leak of Class#dup.

mame	2009-11-14 21:56:16 +0900 (Sat, 14 Nov 2009)

  New Revision: 25768

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

  Log:
    * class.c (rb_mod_init_copy): fix memory leak of Class#dup.
      [ruby-dev:39687]

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/gc.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25767)
+++ ChangeLog	(revision 25768)
@@ -1,3 +1,8 @@
+Sat Nov 14 21:54:46 2009  Yusuke Endoh  <mame@t...>
+
+	* class.c (rb_mod_init_copy): fix memory leak of Class#dup.
+	  [ruby-dev:39687]
+
 Sat Nov 14 17:09:39 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (--with-opt-dir): ignore and suppress a warning.
Index: gc.c
===================================================================
--- gc.c	(revision 25767)
+++ gc.c	(revision 25768)
@@ -1459,8 +1459,8 @@
     return ST_CONTINUE;
 }
 
-static void
-free_m_table(st_table *tbl)
+void
+rb_free_m_table(st_table *tbl)
 {
     st_foreach(tbl, free_method_entry_i, 0);
     st_free_table(tbl);
@@ -1988,7 +1988,7 @@
       case T_MODULE:
       case T_CLASS:
 	rb_clear_cache_by_class((VALUE)obj);
-	free_m_table(RCLASS_M_TBL(obj));
+	rb_free_m_table(RCLASS_M_TBL(obj));
 	if (RCLASS_IV_TBL(obj)) {
 	    st_free_table(RCLASS_IV_TBL(obj));
 	}
Index: class.c
===================================================================
--- class.c	(revision 25767)
+++ class.c	(revision 25768)
@@ -151,6 +151,9 @@
     if (RCLASS_IV_TBL(orig)) {
 	ID id;
 
+	if (RCLASS_IV_TBL(clone)) {
+	    st_free_table(RCLASS_IV_TBL(clone));
+	}
 	RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
 	CONST_ID(id, "__classpath__");
 	st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
@@ -159,6 +162,11 @@
     }
     if (RCLASS_M_TBL(orig)) {
 	struct clone_method_data data;
+
+	if (RCLASS_M_TBL(clone)) {
+	    extern void rb_free_m_table(st_table *tbl);
+	    rb_free_m_table(RCLASS_M_TBL(clone));
+	}
 	data.tbl = RCLASS_M_TBL(clone) = st_init_numtable();
 	data.klass = clone;
 	st_foreach(RCLASS_M_TBL(orig), clone_method,

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

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