From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10302 invoked by alias); 18 Feb 2006 13:38:26 -0000 Received: (qmail 10145 invoked by uid 48); 18 Feb 2006 13:38:23 -0000 Date: Sat, 18 Feb 2006 13:38:00 -0000 Subject: [Bug libgcj/26351] New: Native Momory Leak in ResourceBundle X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "fexx at fexx dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-02/txt/msg02055.txt.bz2 List-Id: 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 (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