< prev index next >
test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp
Print this page
rev 53747 : [mq]: gcc8.2-fixes-strncpy-mlvmtest-01
*** 45,80 ****
strncpy(*dst, pStr, len);
pEnv->ReleaseStringUTFChars(src, pStr);
}
struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) {
char * szName;
char * szSignature;
jclass clazz;
struct MethodName * mn;
if (!NSK_JVMTI_VERIFY(pJvmtiEnv->GetMethodName(method, &szName, NULL, NULL))) {
return NULL;
}
if (!NSK_JVMTI_VERIFY(pJvmtiEnv->GetMethodDeclaringClass(method, &clazz))) {
- NSK_JVMTI_VERIFY(pJvmtiEnv->Deallocate((unsigned char*) szName));
return NULL;
}
if (!NSK_JVMTI_VERIFY(pJvmtiEnv->GetClassSignature(clazz, &szSignature, NULL))) {
! NSK_JVMTI_VERIFY(pJvmtiEnv->Deallocate((unsigned char*) szName));
return NULL;
}
mn = (MethodName*) malloc(sizeof(MethodNameStruct));
strncpy(mn->methodName, szName, sizeof(mn->methodName));
strncpy(mn->classSig, szSignature, sizeof(mn->classSig));
- NSK_JVMTI_VERIFY(pJvmtiEnv->Deallocate((unsigned char*) szName));
- NSK_JVMTI_VERIFY(pJvmtiEnv->Deallocate((unsigned char*) szSignature));
return mn;
}
char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location) {
struct MethodName * pMN;
--- 45,106 ----
strncpy(*dst, pStr, len);
pEnv->ReleaseStringUTFChars(src, pStr);
}
+
+ /**
+ * Helper class to track JVMTI resources, deallocating the resource in the destructor.
+ */
+ class JvmtiResource {
+ private:
+ jvmtiEnv* const _jvmtiEnv;
+ void* const _ptr;
+
+ public:
+ JvmtiResource(jvmtiEnv* jvmtiEnv, void* ptr) : _jvmtiEnv(jvmtiEnv), _ptr(ptr) { }
+
+ ~JvmtiResource() {
+ NSK_JVMTI_VERIFY(_jvmtiEnv->Deallocate((unsigned char*)_ptr));
+ }
+ };
+
struct MethodName * getMethodName(jvmtiEnv * pJvmtiEnv, jmethodID method) {
char * szName;
char * szSignature;
jclass clazz;
struct MethodName * mn;
if (!NSK_JVMTI_VERIFY(pJvmtiEnv->GetMethodName(method, &szName, NULL, NULL))) {
return NULL;
}
+ JvmtiResource szNameResource(pJvmtiEnv, szName);
+
if (!NSK_JVMTI_VERIFY(pJvmtiEnv->GetMethodDeclaringClass(method, &clazz))) {
return NULL;
}
if (!NSK_JVMTI_VERIFY(pJvmtiEnv->GetClassSignature(clazz, &szSignature, NULL))) {
! return NULL;
! }
!
! JvmtiResource szSignatureResource(pJvmtiEnv, szSignature);
!
! if (strlen(szName) + 1 > sizeof(mn->methodName) ||
! strlen(szSignature) + 1 > sizeof(mn->classSig)) {
return NULL;
}
mn = (MethodName*) malloc(sizeof(MethodNameStruct));
+ if (mn == NULL) {
+ return NULL;
+ }
+
strncpy(mn->methodName, szName, sizeof(mn->methodName));
strncpy(mn->classSig, szSignature, sizeof(mn->classSig));
return mn;
}
char * locationToString(jvmtiEnv * pJvmtiEnv, jmethodID method, jlocation location) {
struct MethodName * pMN;
< prev index next >