1.1 --- a/src/share/vm/prims/jniCheck.cpp Fri Oct 04 13:01:07 2013 +0200 1.2 +++ b/src/share/vm/prims/jniCheck.cpp Sat Oct 05 15:18:57 2013 +0200 1.3 @@ -1324,18 +1324,19 @@ 1.4 IN_VM( 1.5 checkString(thr, str); 1.6 ) 1.7 + jchar* newResult = NULL; 1.8 const jchar *result = UNCHECKED()->GetStringChars(env,str,isCopy); 1.9 assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringChars didn't return a copy as expected"); 1.10 - 1.11 - size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination 1.12 - jint* tagLocation = (jint*) AllocateHeap(len * sizeof(jchar) + sizeof(jint), mtInternal); 1.13 - *tagLocation = STRING_TAG; 1.14 - jchar* newResult = (jchar*) (tagLocation + 1); 1.15 - memcpy(newResult, result, len * sizeof(jchar)); 1.16 - // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes 1.17 - // Note that the dtrace arguments for the allocated memory will not match up with this solution. 1.18 - FreeHeap((char*)result); 1.19 - 1.20 + if (result != NULL) { 1.21 + size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination 1.22 + jint* tagLocation = (jint*) AllocateHeap(len * sizeof(jchar) + sizeof(jint), mtInternal); 1.23 + *tagLocation = STRING_TAG; 1.24 + newResult = (jchar*) (tagLocation + 1); 1.25 + memcpy(newResult, result, len * sizeof(jchar)); 1.26 + // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes 1.27 + // Note that the dtrace arguments for the allocated memory will not match up with this solution. 1.28 + FreeHeap((char*)result); 1.29 + } 1.30 functionExit(env); 1.31 return newResult; 1.32 JNI_END 1.33 @@ -1394,18 +1395,19 @@ 1.34 IN_VM( 1.35 checkString(thr, str); 1.36 ) 1.37 + char* newResult = NULL; 1.38 const char *result = UNCHECKED()->GetStringUTFChars(env,str,isCopy); 1.39 assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringUTFChars didn't return a copy as expected"); 1.40 - 1.41 - size_t len = strlen(result) + 1; // + 1 for NULL termination 1.42 - jint* tagLocation = (jint*) AllocateHeap(len + sizeof(jint), mtInternal); 1.43 - *tagLocation = STRING_UTF_TAG; 1.44 - char* newResult = (char*) (tagLocation + 1); 1.45 - strcpy(newResult, result); 1.46 - // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes 1.47 - // Note that the dtrace arguments for the allocated memory will not match up with this solution. 1.48 - FreeHeap((char*)result, mtInternal); 1.49 - 1.50 + if (result != NULL) { 1.51 + size_t len = strlen(result) + 1; // + 1 for NULL termination 1.52 + jint* tagLocation = (jint*) AllocateHeap(len + sizeof(jint), mtInternal); 1.53 + *tagLocation = STRING_UTF_TAG; 1.54 + newResult = (char*) (tagLocation + 1); 1.55 + strcpy(newResult, result); 1.56 + // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes 1.57 + // Note that the dtrace arguments for the allocated memory will not match up with this solution. 1.58 + FreeHeap((char*)result, mtInternal); 1.59 + } 1.60 functionExit(env); 1.61 return newResult; 1.62 JNI_END