changeset 9689:00314b6e9d6b

8036603: Check jdk/src/windows/native/java/lang/ProcessEnvironment_md.c for JNI pending exceptions Summary: added JNI call NULL return checks Reviewed-by: alanb, mchung
author msheppar
date Fri, 20 Jun 2014 16:58:37 +0100
parents 1254832f3d5c
children 74014d58b791
files src/windows/native/java/lang/ProcessEnvironment_md.c
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/lang/ProcessEnvironment_md.c	Thu Jun 12 00:31:27 2014 +0100
+++ b/src/windows/native/java/lang/ProcessEnvironment_md.c	Fri Jun 20 16:58:37 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -32,10 +32,17 @@
 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.  */
@@ -49,10 +56,13 @@
         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);
 }