Mon, 23 Dec 2013 20:56:18 +0400
8029070: memory leak in jmm_SetVMGlobal
Reviewed-by: kvn, dholmes
1.1 --- a/src/share/vm/runtime/globals.cpp Thu Jan 16 13:25:25 2014 -0800 1.2 +++ b/src/share/vm/runtime/globals.cpp Mon Dec 23 20:56:18 2013 +0400 1.3 @@ -759,8 +759,6 @@ 1.4 return true; 1.5 } 1.6 1.7 -// Contract: Flag will make private copy of the incoming value. 1.8 -// Outgoing value is always malloc-ed, and caller MUST call free. 1.9 bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin) { 1.10 Flag* result = Flag::find_flag(name, len); 1.11 if (result == NULL) return false; 1.12 @@ -784,7 +782,6 @@ 1.13 return true; 1.14 } 1.15 1.16 -// Contract: Flag will make private copy of the incoming value. 1.17 void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin) { 1.18 Flag* faddr = address_of_flag(flag); 1.19 guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
2.1 --- a/src/share/vm/runtime/globals.hpp Thu Jan 16 13:25:25 2014 -0800 2.2 +++ b/src/share/vm/runtime/globals.hpp Mon Dec 23 20:56:18 2013 +0400 2.3 @@ -390,6 +390,8 @@ 2.4 2.5 static bool ccstrAt(char* name, size_t len, ccstr* value); 2.6 static bool ccstrAt(char* name, ccstr* value) { return ccstrAt(name, strlen(name), value); } 2.7 + // Contract: Flag will make private copy of the incoming value. 2.8 + // Outgoing value is always malloc-ed, and caller MUST call free. 2.9 static bool ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin); 2.10 static bool ccstrAtPut(char* name, ccstr* value, Flag::Flags origin) { return ccstrAtPut(name, strlen(name), value, origin); } 2.11
3.1 --- a/src/share/vm/runtime/globals_extension.hpp Thu Jan 16 13:25:25 2014 -0800 3.2 +++ b/src/share/vm/runtime/globals_extension.hpp Mon Dec 23 20:56:18 2013 +0400 3.3 @@ -201,6 +201,7 @@ 3.4 static void uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin); 3.5 static void uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin); 3.6 static void doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin); 3.7 + // Contract: Flag will make private copy of the incoming value 3.8 static void ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin); 3.9 3.10 static bool is_default(CommandLineFlag flag);
4.1 --- a/src/share/vm/services/management.cpp Thu Jan 16 13:25:25 2014 -0800 4.2 +++ b/src/share/vm/services/management.cpp Mon Dec 23 20:56:18 2013 +0400 4.3 @@ -1824,7 +1824,7 @@ 4.4 "This flag is not writeable."); 4.5 } 4.6 4.7 - bool succeed; 4.8 + bool succeed = false; 4.9 if (flag->is_bool()) { 4.10 bool bvalue = (new_value.z == JNI_TRUE ? true : false); 4.11 succeed = CommandLineFlags::boolAtPut(name, &bvalue, Flag::MANAGEMENT); 4.12 @@ -1856,6 +1856,9 @@ 4.13 } 4.14 ccstr svalue = java_lang_String::as_utf8_string(str); 4.15 succeed = CommandLineFlags::ccstrAtPut(name, &svalue, Flag::MANAGEMENT); 4.16 + if (succeed) { 4.17 + FREE_C_HEAP_ARRAY(char, svalue, mtInternal); 4.18 + } 4.19 } 4.20 assert(succeed, "Setting flag should succeed"); 4.21 JVM_END