JNI global references leak when native method registration fails
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 66/100
Hướng nghiên cứu
Bắt đầu trong native/dispatch.c tại Java_com_sun_jna_Native_registerMethod, đặc biệt là đường dẫn dọn dẹp được thực hiện sau khi ffi_prep_cif, ffi_closure_alloc hoặc ffi_prep_closure_loc thất bại. Theo dõi quyền sở hữu của closure_method, from_native, to_native, closure_arg_types, encoding và FFI closure, sau đó xác minh rằng các lần đăng ký thất bại sẽ giải phóng chúng, trong khi các lần đăng ký thành công vẫn chuyển việc dọn dẹp cho Native_unregister.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Java_com_sun_jna_Native_registerMethod creates persistent JNI references before several fallible FFI initialization steps.
Affected code:
https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/native/dispatch.c#L3553-L3587
If ffi_prep_cif, ffi_closure_alloc, or ffi_prep_closure_loc fails, execution jumps to cleanup. That path frees data without calling DeleteGlobalRef for data->closure_method.
Because registration did not complete, Native_unregister cannot release this reference later.
Impact
Each failed registration permanently retains the reflected Java Method and potentially its class-loader object graph until JVM shutdown. Repeated failures may cause persistent memory growth.
The same cleanup path also omits some related resources, including weak global references, closure_arg_types, encoding, and an allocated FFI closure.
Suggested fix
Before freeing data on failure:
- Delete
closure_methodwithDeleteGlobalRef. - Delete any
from_nativeandto_nativeweak global references. - Free all allocated arrays, encoding data, and FFI closure memory.
Successful registrations should continue to transfer ownership to Native_unregister.
- Ngôn ngữ chính
- Java
- Star
- 8.9k
- Fork
- 1.7k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của java-native-access/jna
-
Incorrect mapping of c.s.j.platform.unix.solaris.LibKstat.KstatCtlCó thể đã có người làm @dbwiddis đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
java-native-access/jna#1740 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
java-native-access/jna#1736 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrectCó thể đã có người làm @marktech0813 đã nhận 332 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
java-native-access/jna#1700 · 11 bình luận ·
-
feature request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
java-native-access/jna#1698 · 1 bình luận ·
Tất cả issue của java-native-access/jna
Issue tương tự
-
Fix Math.ceilDiv wrong result for exact positive divisionsCó thể đã có người làm @pamod-madubashana đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
scala-native/scala-native#5094 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] AI unread message badge counts a batch of new bubbles as one messageCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/rocketmq-dashboard#5784 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[i18n] 安装实例完成后的成功提示未正确本地化Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
PCL-Community/PCL-CE#3658 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
apache/skywalking#14127 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày