diff src/share/native/sun/management/Flag.c @ 2282:83c34a6b1458

6924497: HotSpotDiagnosticsMXBean.getDiagnosticOptions throws NPE Summary: Check if the element in the flags array is non-null to filter unsupported flags Reviewed-by: dcubed
author mchung
date Mon, 08 Feb 2010 23:02:28 -0800
parents 37a05a11f281
children f8c9a5e3f5db
line wrap: on
line diff
--- a/src/share/native/sun/management/Flag.c	Sat Feb 06 09:26:57 2010 -0800
+++ b/src/share/native/sun/management/Flag.c	Mon Feb 08 23:02:28 2010 -0800
@@ -84,6 +84,7 @@
 
     jint num_flags, i, index;
     jmmVMGlobal* globals;
+    size_t gsize;
     const char* class_name = "sun/management/Flag";
     const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V";
     jobject origin;
@@ -100,12 +101,14 @@
         return 0;
     }
 
-    globals = (jmmVMGlobal*) malloc(count * sizeof(jmmVMGlobal));
+    gsize = count * sizeof(jmmVMGlobal);
+    globals = (jmmVMGlobal*) malloc(gsize);
     if (globals == NULL) {
         JNU_ThrowOutOfMemoryError(env, 0);
         return 0;
     }
 
+    memset(globals, 0, gsize);
     num_flags = jmm_interface->GetVMGlobals(env, names, globals, count);
     if (num_flags == 0) {
         free(globals);