JNI local-reference accumulation in the string array helpers
まだ誰も着手していません。
評価
調査の方向性
まず dataset/src/main/cpp/jni_util.cc の ToStringVector と、dataset/src/main/cpp/jni_wrapper.cc の ToStringMap および LoadNamedTables を読み、各 GetObjectArrayElement 呼び出しに注目します。取得したすべてのローカル参照が通常のパスと JniThrow() のパスで削除されるようにしてください。完了とは、現在の反復の参照が放置されたまま残っていないことを意味します。
索引モデルが issue の本文から書いたものです。
説明
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().
- 主要言語
- Java
- スター
- 95
- フォーク
- 154
- 平均マージ
- 2日 10時間
- マージ済み PR(30日)
- 11
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/arrow-java のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
apache/arrow-java#1261 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/arrow-java#1236 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/arrow-java#1230 ·
-
Type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
apache/arrow-java#1205 ·
-
Type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/arrow-java#1196 · コメント 1 件 ·
apache/arrow-java の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 オープンbug frontend maui-pilot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
objectionary/eo-graphs#74 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100