You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/01/29 17:30:03 UTC
svn commit: r501090 -
/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c
Author: tellison
Date: Mon Jan 29 08:30:02 2007
New Revision: 501090
URL: http://svn.apache.org/viewvc?view=rev&rev=501090
Log:
Apply patch HARMONY-3008 ([classlib][instrument]Releases byte array too early in the native code of redefine classes)
Modified:
harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c
Modified: harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c?view=diff&rev=501090&r1=501089&r2=501090
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c (original)
+++ harmony/enhanced/classlib/trunk/modules/instrument/src/main/native/instrument/shared/instrument.c Mon Jan 29 08:30:02 2007
@@ -90,6 +90,16 @@
}
}
+void cleanup(JNIEnv* env, jvmtiClassDefinition *class_definitions, int filled_class_definitions){
+ PORT_ACCESS_FROM_ENV (env);
+ int i;
+ for(i = 0;i<filled_class_definitions;i++){
+ hymem_free_memory((jbyte *)class_definitions[i].class_bytes);
+ }
+ hymem_free_memory(class_definitions);
+ return;
+}
+
/*
* This file contains native methods implementation for org/apache/harmony/instrument/internal/InstrumentationImpl
*/
@@ -225,25 +235,21 @@
int class_byte_count;
jobject obj_ClassDefinition=(*env)->GetObjectArrayElement(env, javaClassDefArr, index);
jbyteArray jclass_bytes;
- jboolean copy;
jbyte* class_bytes;
jclass klass=(jclass)(*env)->CallObjectMethod(env, obj_ClassDefinition, method_get_class);
if (NULL == klass){
- hymem_free_memory(class_definitions);
+ cleanup(env, class_definitions, index);
return;
}
jclass_bytes =(jbyteArray)(*env)->CallObjectMethod(env, obj_ClassDefinition, method_get_data);
- copy = JNI_TRUE;
- class_bytes = (*env)->GetByteArrayElements(env, jclass_bytes, ©);
+ class_byte_count = (*env)->GetArrayLength(env, jclass_bytes);
+ class_bytes = (jbyte *)hymem_allocate_memory(sizeof(jbyte)*class_byte_count);
if(NULL == class_bytes){
- hymem_free_memory(class_definitions);
+ cleanup(env, class_definitions, index);
return;
}
- class_byte_count = (*env)->GetArrayLength(env, jclass_bytes);
- if(copy == JNI_TRUE){
- (*env)->ReleaseByteArrayElements(env,jclass_bytes, class_bytes, JNI_ABORT);
- }
-
+ (*env)->GetByteArrayRegion(env,jclass_bytes,0,class_byte_count,class_bytes);
+
//construct a jvmtiClassDefinition element
class_definitions[index].klass=klass;
class_definitions[index].class_bytes=class_bytes;
@@ -260,7 +266,7 @@
throw_exception(env,err);
}
//free memory
- hymem_free_memory(class_definitions);
+ cleanup(env, class_definitions, length);
return;
}