[vmkit-commits] [vmkit] r73410 - /vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Jun 15 13:18:44 PDT 2009


Author: geoffray
Date: Mon Jun 15 15:18:32 2009
New Revision: 73410

URL: http://llvm.org/viewvc/llvm-project?rev=73410&view=rev
Log:
The getenv implementation in classpath has a memory leak. Implement our own.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=73410&r1=73409&r2=73410&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon Jun 15 15:18:32 2009
@@ -415,6 +415,17 @@
 // Defined in Classpath/ClasspathVMClassLoader.cpp
 extern "C" ArrayObject* nativeGetBootPackages();
 
+extern "C" JavaString* nativeGetenv(JavaString* str) {
+  char* buf = str->strToAsciiz();
+  char* res = getenv(buf);
+  delete[] buf;
+  if (res) {
+    Jnjvm* vm = JavaThread::get()->getJVM();
+    return vm->asciizToStr(res);
+  }
+  return 0;
+}
+
 void Classpath::initialiseClasspath(JnjvmClassLoader* loader) {
 
   newClassLoader = 
@@ -799,6 +810,11 @@
   
   // Don't compile methods here, we still don't know where to allocate Java
   // strings.
+  
+  JavaMethod* getEnv =
+    UPCALL_METHOD(loader, "java/lang/VMSystem", "getenv",
+                  "(Ljava/lang/String;)Ljava/lang/String;", ACC_STATIC);
+  getEnv->setCompiledPtr((void*)(intptr_t)nativeGetenv, "nativeGetenv");
 
   JavaMethod* getCallingClass =
     UPCALL_METHOD(loader, "gnu/classpath/VMStackWalker", "getCallingClass",





More information about the vmkit-commits mailing list