[Bug libgcj/60282] New: memory leak - Double from string, _Jv_Balloc

antoine.dymond at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Feb 20 08:23:00 GMT 2014


            Bug ID: 60282
           Summary: memory leak - Double from string, _Jv_Balloc
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcj
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoine.dymond at gmail dot com

I believe there is memory leak when creating a Double from a string. For

double value = (new Double("3.14")).doubleValue();

Valgrind output:

== 56 bytes in 1 blocks are definitely lost in loss record 17 of 31
==    at 0x4C2A2DB: malloc (in
==    by 0x6DE98D1: _Jv_Balloc (in /usr/lib/x86_64-linux-gnu/libgcj.so.14.0.0)
==    by 0x6DEA378: _Jv_d2b (in /usr/lib/x86_64-linux-gnu/libgcj.so.14.0.0)
==    by 0x6DE4BDB: _Jv_dtoa_r (in /usr/lib/x86_64-linux-gnu/libgcj.so.14.0.0)
==    by 0x6DE5F0F: _Jv_dtoa (in /usr/lib/x86_64-linux-gnu/libgcj.so.14.0.0)
==    by 0x65CBF9D: java::lang::String* java::lang::VMDouble::toString(double,
bool) (in /usr/lib/x86_64-linux-gnu/libgcj.so.14.0.0)
==    by 0x6926404: java::lang::String* java::lang::Double::toString(double)
(in /usr/lib/x86_64-linux-gnu/libgcj.so.14.0.0)
==    by 0x6926418: java::lang::AbstractStringBuffer*
java::lang::AbstractStringBuffer::append(double) (in
==    by 0x69264D8: java::lang::StringBuilder*
java::lang::StringBuilder::append(double) (in

Reconstruct info

$ more double_from_str.java 

public class double_from_str {
    public static void convert(){
    double value = (new Double("3.14")).doubleValue();
    System.out.printf("pi = " + value + "\n");


$ more main.cpp

#include <stdio.h>
#include <gcj/cni.h>
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
#include <java/lang/Throwable.h>
#include "double_from_str.h"

int main(int argc, char *argv[])
  using namespace java::lang;
      JvAttachCurrentThread(NULL, NULL);
      return 0;
  catch (Throwable *t)
      printf("Unhandled Java exception\n");
      return 1;

$ make -B

gcj -fPIC -c double_from_str.java    
gcj -C double_from_str.java
gcjh double_from_str.class
gcj -g -lstdc++ double_from_str.o main.cpp -o main.o
cc1plus: warning: command line option
‘-fbootclasspath=./:/usr/share/java/libgcj-4.8.jar’ is valid for Java but not
for C++ [enabled by default]

$ valgrind --leak-check=yes ./main.o


$ apt-cache show valgrind
Architecture: amd64
Version: 1:3.8.1-4ubuntu1

More information about the Java-prs mailing list