src/windows/native/java/lang/ProcessEnvironment_md.c
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -30,14 +30,21 @@
static jstring
environmentBlock9x(JNIEnv *env)
{
int i;
- jmethodID String_init_ID =
- (*env)->GetMethodID(env, JNU_ClassString(env), "<init>", "([B)V");
+ jmethodID String_init_ID;
jbyteArray bytes;
- jbyte *blockA = (jbyte *) GetEnvironmentStringsA();
+ jbyte *blockA;
+ jclass string_class;
+
+ string_class= JNU_ClassString(env);
+ CHECK_NULL_RETURN(string_class, NULL);
+ String_init_ID =
+ (*env)->GetMethodID(env, string_class, "<init>", "([B)V");
+ CHECK_NULL_RETURN(String_init_ID);
+ blockA = (jbyte *) GetEnvironmentStringsA();
if (blockA == NULL) {
/* Both GetEnvironmentStringsW and GetEnvironmentStringsA
* failed. Out of memory is our best guess. */
JNU_ThrowOutOfMemoryError(env, "GetEnvironmentStrings failed");
return NULL;
@@ -47,14 +54,17 @@
legitimately consist of a single "\0". */
for (i = 0; blockA[i];)
while (blockA[i++])
;
- if ((bytes = (*env)->NewByteArray(env, i)) == NULL) return NULL;
+ if ((bytes = (*env)->NewByteArray(env, i)) == NULL) {
+ FreeEnvironmentStringsA(blockA);
+ return NULL;
+ }
(*env)->SetByteArrayRegion(env, bytes, 0, i, blockA);
FreeEnvironmentStringsA(blockA);
- return (*env)->NewObject(env, JNU_ClassString(env),
+ return (*env)->NewObject(env, string_class,
String_init_ID, bytes);
}
/* Returns a Windows style environment block, discarding final trailing NUL */
JNIEXPORT jstring JNICALL