This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: memory leak in java/lang/natClass.cc


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I found another memory leak in java/lang/natClass.cc in 
_Jv_PrepareConstantTimeTables. The attached patch moves two abortion 
checks before the allocation of memory.

Okay to commit to trunk ?


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/AcYMWSOgCCdjSDsRAq4hAKCMjPhZFGkMYSq/uxxJDKHRsknSxgCfT36q
dR3VbdP6vI3e3+PUdp+R2eM=
=Fpdw
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2013
diff -u -b -B -r1.2013 ChangeLog
--- ChangeLog	1 Jul 2003 14:42:37 -0000	1.2013
+++ ChangeLog	1 Jul 2003 17:23:14 -0000
@@ -1,5 +1,12 @@
 2003-07-01  Michael Koch  <konqueror@gmx.de>
 
+	* java/lang/natClass.cc
+	(_Jv_PrepareConstantTimeTables): Move two checks for aborts before the
+	allocation of memory. This prevents to allocate memory which gets
+	never freed.
+
+2003-07-01  Michael Koch  <konqueror@gmx.de>
+
 	* gnu/gcj/convert/natIconv.cc
 	(iconv_init): Fixed possible memory leak by releasing allocated iconv
 	handle.
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.62
diff -u -b -B -r1.62 natClass.cc
--- java/lang/natClass.cc	1 May 2003 21:36:18 -0000	1.62
+++ java/lang/natClass.cc	1 Jul 2003 17:23:15 -0000
@@ -1141,6 +1141,17 @@
       klass->depth++;
     }
 
+  if (java::lang::reflect::Modifier::isAbstract (klass->accflags))
+    return;
+  
+  // Optimization: If class implements no interfaces, use a common
+  // predefined interface table.
+  if (!has_interfaces)
+    {
+      klass->idt = &null_idt;
+      return;
+    }
+
   // We do class member testing in constant time by using a small table 
   // of all the ancestor classes within each class. The first element is 
   // a pointer to the current class, and the rest are pointers to the 
@@ -1156,17 +1167,6 @@
       klass0 = klass0->superclass;
     }
     
-  if (java::lang::reflect::Modifier::isAbstract (klass->accflags))
-    return;
-  
-  // Optimization: If class implements no interfaces, use a common
-  // predefined interface table.
-  if (!has_interfaces)
-    {
-      klass->idt = &null_idt;
-      return;
-    }
-
   klass->idt = 
     (_Jv_IDispatchTable *) _Jv_Malloc (sizeof (_Jv_IDispatchTable));
     

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]