JNI local-reference accumulation in the string array helpers
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 75/100
Piste de recherche
Commencez par lire ToStringVector dans dataset/src/main/cpp/jni_util.cc ainsi que ToStringMap et LoadNamedTables dans dataset/src/main/cpp/jni_wrapper.cc, en vous concentrant sur chaque appel à GetObjectArrayElement. Assurez-vous que chaque référence locale acquise est supprimée sur les chemins normaux et les chemins JniThrow() ; c’est terminé lorsqu’aucune référence de l’itération courante ne reste abandonnée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug, including details regarding any error messages, version, and platform.
There is a JNI local-reference issue in the dataset helpers that convert Java String[] arrays into C++ containers. They get each element with GetObjectArrayElement() and convert it, but never delete the resulting local reference.
Files:
dataset/src/main/cpp/jni_util.ccdataset/src/main/cpp/jni_wrapper.cc
Functions:
ToStringVector(jni_util.cc)ToStringMap,LoadNamedTables(jni_wrapper.cc)
Relevant code in ToStringVector():
std::vector<std::string> ToStringVector(JNIEnv* env, jobjectArray& str_array) {
int length = env->GetArrayLength(str_array);
std::vector<std::string> vector;
for (int i = 0; i < length; i++) {
auto string = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i));
vector.push_back(JStringToCString(env, string));
}
return vector;
}
JStringToCString() does correctly release the native UTF chars it acquires:
const char* chars = env->GetStringUTFChars(string, nullptr);
std::string ret(chars);
env->ReleaseStringUTFChars(string, chars);
return ret;
but that release only matches GetStringUTFChars(). It does not delete the jstring local reference that GetObjectArrayElement() returned, so one reference remains live per element until the native method returns.
ToStringMap() has the same pattern with two references per iteration:
for (int i = 0; i < length; i += 2) {
auto key = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i));
auto value = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i + 1));
map[JStringToCString(env, key)] = JStringToCString(env, value);
}
LoadNamedTables() also takes two per iteration, and has three JniThrow() exits inside the loop body — the odd-length check and the two std::stol failure handlers — so on those paths the references acquired in the current iteration are abandoned mid-loop.
These are local references, so they are reclaimed when the native method returns, and the inputs are option maps, partition columns, and named-table lists — typically tens of entries. There is no observable leak or reachable failure here; the reference count is simply higher than necessary for the duration of the call.
Suggested fix:
auto string = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i));
vector.push_back(JStringToCString(env, string));
env->DeleteLocalRef(string);
For the key/value loops, delete both key and value, including on the JniThrow() paths in LoadNamedTables().
- Langage dominant
- Java
- Étoiles
- 95
- Forks
- 154
- Merge moyen
- 2 j 10 h
- PR mergées (30 j)
- 11
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/arrow-java
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
apache/arrow-java#1261 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
apache/arrow-java#1236 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
apache/arrow-java#1230 ·
-
Type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
apache/arrow-java#1205 ·
-
Type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
apache/arrow-java#1196 · 1 commentaire ·
Toutes les issues de apache/arrow-java
Issues similaires
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Ouvertearea/plugin
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Add canonical URLs and a sitemap Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
apache/rocketmq-dashboard#5064 ·
-
Consent portal: creating a duplicate Purpose shows a generic error instead of "already exists" Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
wso2/dpdp-accelerator#287 ·