From da844719ab0d4862004bc2add1e6346d7a7c7912 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 4 Jul 2007 12:15:03 -0600 Subject: [PATCH] fix off-by-one thinko in GetStringUTFChars; call dlclose() in ~Library() --- makefile | 2 +- src/main.cpp | 10 ++++++++++ src/vm.cpp | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 81d9ae93cf..00cb5e6ddc 100644 --- a/makefile +++ b/makefile @@ -127,7 +127,7 @@ fast-cflags = $(fast) $(cflags) classpath-sources = $(shell find $(classpath)/java -name '*.java') classpath-classes = $(call java-classes,$(classpath-sources),$(classpath)) -input = $(bld)/classes/TestExceptions.class +input = $(bld)/classes/Hello.class input-depends = \ $(classpath-classes) \ $(jni-library) diff --git a/src/main.cpp b/src/main.cpp index 5c66f63896..b4be302c8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,6 +236,12 @@ class System: public vm::System { } virtual void dispose() { + if (Verbose) { + fprintf(stderr, "close %p\n", p); + } + + dlclose(p); + if (next_) { next_->dispose(); } @@ -335,6 +341,10 @@ class System: public vm::System { void* p = dlopen(buffer, RTLD_LAZY); if (p) { + if (Verbose) { + fprintf(stderr, "open %s as %p\n", buffer, p); + } + *lib = new (vm::System::allocate(sizeof(Library))) Library(this, p, next); return 0; diff --git a/src/vm.cpp b/src/vm.cpp index 2f04fcb77e..5937c00fdf 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -2757,7 +2757,8 @@ GetStringUTFChars(JNIEnv* e, jstring s, jboolean* isCopy) char* chars = 0; if (LIKELY(s)) { - chars = static_cast(t->vm->system->allocate(stringLength(t, *s))); + chars = static_cast + (t->vm->system->allocate(stringLength(t, *s) + 1)); memcpy(chars, &byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)),