public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/26351]  New: Native Momory Leak in ResourceBundle
@ 2006-02-18 13:38 fexx at fexx dot org
  2006-02-20  2:24 ` [Bug libgcj/26351] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: fexx at fexx dot org @ 2006-02-18 13:38 UTC (permalink / raw)
  To: gcc-bugs

Invoking java.util.ResourceBundle.getBundle(String) leaks some native memory. 
A small sample program is attached.  If you run it, you will see that the
process' virual memory size keeps growing while Java heap consumption stays at
a same level after some iteration.

The problem is in gnu.gcj.runtime.StackTrace.fillInStackTrace (a native code)
invoked through gnu.gcj.runtime.StackTrace.classAt through
java.lang.Class.forName through java.util.ResourceBundle.tryBundle.  When the
native method fillInStackTrace is invoked by a method other than its
constructor, a native memory allocated through _Jv_Malloc and stored in addrs
is discarded without _Jv_Free'ed.

I exprerienced this problem on Windows (MinGW) but I belive it is common to
other platforms.

A suggested fix is attached:

--- libjava/gnu/gcj/runtime/natStackTrace.orig.cc       2003-10-02
16:10:34.000000000 +0900
+++ libjava/gnu/gcj/runtime/natStackTrace.cc    2006-02-17 00:01:52.529572700
+0900
@@ -85,6 +85,8 @@
   else
     frame = NULL;

+  if (addrs != NULL)
+    _Jv_Free (addrs);
   addrs = reinterpret_cast<gnu::gcj::RawData *> (frame);
 #else // HAVE_BACKTRACE
   (void)maxlen;

---

A sample program to reproduce the problem follows:

import java.util.ResourceBundle;
import java.util.MissingResourceException;

public class Leak {
    public static void main(String[] args) {
        final Runtime r = Runtime.getRuntime();
        for (;;) {
            for (int i = 0; i < 10000; i++) {
                try {
                    ResourceBundle.getBundle("nothing");
                } catch (MissingResourceException e) {
                }
            }
            System.out.println(r.freeMemory() + "/" + r.totalMemory());
        }
    }
}


-- 
           Summary: Native Momory Leak in ResourceBundle
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fexx at fexx dot org
 GCC build triplet: mingw32
  GCC host triplet: mingw32
GCC target triplet: mingw32


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26351


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-03-07 17:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-18 13:38 [Bug libgcj/26351] New: Native Momory Leak in ResourceBundle fexx at fexx dot org
2006-02-20  2:24 ` [Bug libgcj/26351] " pinskia at gcc dot gnu dot org
2006-02-20 19:47 ` mckinlay at redhat dot com
2006-02-21 14:52 ` fexx at fexx dot org
2006-03-07 16:58 ` tromey at gcc dot gnu dot org
2006-03-07 17:07 ` tromey at gcc dot gnu dot org
2006-03-07 17:08 ` tromey at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).