Make GetErrorName allocate the output buffer.
Previously we were simply returning a static pointer which isn't
allowed by the spec.
Test: mma -j40 test-art-host
Change-Id: I84cfb81e58d479c7c0d5ee352f5b005183895c82
diff --git a/runtime/openjdkjvmti/OpenjdkJvmTi.cc b/runtime/openjdkjvmti/OpenjdkJvmTi.cc
index 98c4c3a..1cfd14e 100644
--- a/runtime/openjdkjvmti/OpenjdkJvmTi.cc
+++ b/runtime/openjdkjvmti/OpenjdkJvmTi.cc
@@ -1067,8 +1067,15 @@
ENSURE_NON_NULL(name_ptr);
switch (error) {
#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : do { \
- *name_ptr = const_cast<char*>("JVMTI_ERROR_"#e); \
- return OK; \
+ jvmtiError res = CopyString(env, \
+ "JVMTI_ERROR_"#e, \
+ reinterpret_cast<unsigned char**>(name_ptr)); \
+ if (res != OK) { \
+ *name_ptr = nullptr; \
+ return res; \
+ } else { \
+ return OK; \
+ } \
} while (false)
ERROR_CASE(NONE);
ERROR_CASE(INVALID_THREAD);
@@ -1120,8 +1127,15 @@
ERROR_CASE(INVALID_ENVIRONMENT);
#undef ERROR_CASE
default: {
- *name_ptr = const_cast<char*>("JVMTI_ERROR_UNKNOWN");
- return ERR(ILLEGAL_ARGUMENT);
+ jvmtiError res = CopyString(env,
+ "JVMTI_ERROR_UNKNOWN",
+ reinterpret_cast<unsigned char**>(name_ptr));
+ if (res != OK) {
+ *name_ptr = nullptr;
+ return res;
+ } else {
+ return ERR(ILLEGAL_ARGUMENT);
+ }
}
}
}