# HG changeset patch # User iignatyev # Date 1387817778 -14400 # Node ID 6c583aa36bc90cbb3c77c8daac9a82063e92fda9 # Parent 27c84ba76954890cec93b4437d482ae64fc10e2a 8029070: memory leak in jmm_SetVMGlobal Reviewed-by: kvn, dholmes diff -r 27c84ba76954 -r 6c583aa36bc9 src/share/vm/runtime/globals.cpp --- a/src/share/vm/runtime/globals.cpp Wed Dec 18 23:09:57 2013 +0400 +++ b/src/share/vm/runtime/globals.cpp Mon Dec 23 20:56:18 2013 +0400 @@ -702,8 +702,6 @@ return true; } -// Contract: Flag will make private copy of the incoming value. -// Outgoing value is always malloc-ed, and caller MUST call free. bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin) { Flag* result = Flag::find_flag(name, len); if (result == NULL) return false; @@ -726,7 +724,6 @@ return true; } -// Contract: Flag will make private copy of the incoming value. void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin) { Flag* faddr = address_of_flag(flag); guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type"); diff -r 27c84ba76954 -r 6c583aa36bc9 src/share/vm/runtime/globals.hpp --- a/src/share/vm/runtime/globals.hpp Wed Dec 18 23:09:57 2013 +0400 +++ b/src/share/vm/runtime/globals.hpp Mon Dec 23 20:56:18 2013 +0400 @@ -376,6 +376,8 @@ static bool ccstrAt(char* name, size_t len, ccstr* value); static bool ccstrAt(char* name, ccstr* value) { return ccstrAt(name, strlen(name), value); } + // Contract: Flag will make private copy of the incoming value. + // Outgoing value is always malloc-ed, and caller MUST call free. static bool ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin); static bool ccstrAtPut(char* name, ccstr* value, Flag::Flags origin) { return ccstrAtPut(name, strlen(name), value, origin); } diff -r 27c84ba76954 -r 6c583aa36bc9 src/share/vm/runtime/globals_extension.hpp --- a/src/share/vm/runtime/globals_extension.hpp Wed Dec 18 23:09:57 2013 +0400 +++ b/src/share/vm/runtime/globals_extension.hpp Mon Dec 23 20:56:18 2013 +0400 @@ -201,6 +201,7 @@ static void uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin); static void uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin); static void doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin); + // Contract: Flag will make private copy of the incoming value static void ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin); static bool is_default(CommandLineFlag flag); diff -r 27c84ba76954 -r 6c583aa36bc9 src/share/vm/services/management.cpp --- a/src/share/vm/services/management.cpp Wed Dec 18 23:09:57 2013 +0400 +++ b/src/share/vm/services/management.cpp Mon Dec 23 20:56:18 2013 +0400 @@ -1821,7 +1821,7 @@ "This flag is not writeable."); } - bool succeed; + bool succeed = false; if (flag->is_bool()) { bool bvalue = (new_value.z == JNI_TRUE ? true : false); succeed = CommandLineFlags::boolAtPut(name, &bvalue, Flag::MANAGEMENT); @@ -1841,6 +1841,9 @@ } ccstr svalue = java_lang_String::as_utf8_string(str); succeed = CommandLineFlags::ccstrAtPut(name, &svalue, Flag::MANAGEMENT); + if (succeed) { + FREE_C_HEAP_ARRAY(char, svalue, mtInternal); + } } assert(succeed, "Setting flag should succeed"); JVM_END