JNI crashes from IsSameObject in swig_connect_director
"Holle, Jess" <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CY4PR1701MB17824673D5B027EC8F2DFC8DB5400@CY4PR1701MB1782.namprd17.prod.outlook.com> |
I am seeing 2 different, strange JNI crashes from within JNI's IsSameObject in generated swig_connect_director methods on Android, i.e. from
bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);
In one case I get:
JNI DETECTED ERROR IN APPLICATION: use of deleted local reference 0xd25
I can readily reproduce this issue by running while connected to Android Studio's memory profiler.
In the other case I'm getting reports of
JNI ERROR (app bug): attempt to use stale Local 0x29 (should be 0x21)'
Yet 'baseclass' here has been found and a global reference created for it just above this and 'jcls' is passed down in the same JNIEnv on stack from the result of
jenv->GetObjectClass(jself)
in a Java_*_1director_1connect call.
The only thing that's making any sense to me at this point is a race condition in the code:
if (!baseclass) {
baseclass = jenv->FindClass("com/ptc/daltonplayer/atomSDK/ActionDelegate");
if (!baseclass) return;
baseclass = (jclass) jenv->NewGlobalRef(baseclass);
}
This code has a clear race condition - as it stuff `baseclass` into a static as a local reference and *then* turns around and replace it with a global reference.
I would like to propose a simple fix to this race condition:
if (!baseclass) {
jclass localBaseclass = jenv->FindClass("com/ptc/daltonplayer/atomSDK/ActionDelegate");
if (!localBaseclass) return;
baseclass = (jclass) jenv->NewGlobalRef(localBaseclass);
}
--
Jess Holle
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user