Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Free Local Refs manually due to Android local ref. count limits #1179

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Enchancement: Support SENTRY_TRACES_SAMPLE_RATE conf. via env variables (#1171)
* Enhancement: Pass request to CustomSamplingContext in Spring integration (#1172)
* Fix: Free Local Refs manually due to Android local ref. count limits

# 4.0.0-alpha.3

Expand Down
18 changes: 18 additions & 0 deletions sentry-android-ndk/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e
jstring value = (*env)->NewStringUTF(env, value_v);

(*env)->CallVoidMethod(env, image, image_addr_method, value);

// Local refs (eg NewStringUTF) are freed automatically when the native method
// returns, but if you're iterating a large array, it's recommended to release
// manually due to allocation limits (512) on Android < 8 or OOM.
// https://developer.android.com/training/articles/perf-jni.html#local-and-global-references
(*env)->DeleteLocalRef(env, value);
}

sentry_value_t image_size_t = sentry_value_get_by_key(image_t, "image_size");
Expand All @@ -325,6 +331,8 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e
jstring value = (*env)->NewStringUTF(env, value_v);

(*env)->CallVoidMethod(env, image, code_file_method, value);

(*env)->DeleteLocalRef(env, value);
}

sentry_value_t code_type_t = sentry_value_get_by_key(image_t, "type");
Expand All @@ -334,6 +342,8 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e
jstring value = (*env)->NewStringUTF(env, value_v);

(*env)->CallVoidMethod(env, image, type_method, value);

(*env)->DeleteLocalRef(env, value);
}

sentry_value_t debug_id_t = sentry_value_get_by_key(image_t, "debug_id");
Expand All @@ -343,6 +353,8 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e
jstring value = (*env)->NewStringUTF(env, value_v);

(*env)->CallVoidMethod(env, image, debug_id_method, value);

(*env)->DeleteLocalRef(env, value);
}

sentry_value_t code_id_t = sentry_value_get_by_key(image_t, "code_id");
Expand All @@ -352,6 +364,8 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e
jstring value = (*env)->NewStringUTF(env, value_v);

(*env)->CallVoidMethod(env, image, code_id_method, value);

(*env)->DeleteLocalRef(env, value);
}

// not needed on Android, but keeping for forward compatibility
Expand All @@ -362,9 +376,13 @@ Java_io_sentry_android_ndk_NativeModuleListLoader_nativeLoadModuleList(JNIEnv *e
jstring value = (*env)->NewStringUTF(env, value_v);

(*env)->CallVoidMethod(env, image, debug_file_method, value);

(*env)->DeleteLocalRef(env, value);
}

(*env)->SetObjectArrayElement(env, image_list, i, image);

(*env)->DeleteLocalRef(env, image);
}
}

Expand Down