Global reference leak in `Callback.bind()`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Đọc bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c, tập trung vào CALLBACK_NATIVE(bind) và nhánh fail của nó; so sánh nhánh đó với phần dọn dẹp trong CALLBACK_NATIVE(unbind). Kiểm tra các bài kiểm thử liên quan đến callback hoặc các bước kiểm tra build native của repository, sau đó xác minh rằng nếu tạo tham chiếu toàn cục thứ hai thất bại thì sẽ không còn tham chiếu nào hoặc slot nào được khởi tạo dở dang.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I found a possible JNI global reference leak in Callback.bind() when native callback registration fails halfway through initialization.
File: bundles/org.eclipse.swt/Eclipse SWT/common/library/callback.c
Function: CALLBACK_NATIVE(bind)
Relevant code:
for (i=0; i<MAX_CALLBACKS; i++) {
if (!callbackData[i].callback) {
if ((callbackData[i].callback = (*env)->NewGlobalRef(env, callbackObject)) == NULL) goto fail;
if ((callbackData[i].object = (*env)->NewGlobalRef(env, object)) == NULL) goto fail;
callbackData[i].isStatic = isStatic;
callbackData[i].isArrayBased = isArrayBased;
callbackData[i].argCount = argCount;
callbackData[i].errorResult = errorResult;
callbackData[i].methodID = mid;
result = (jlong) fnx_array[argCount][i];
break;
}
}
fail:
if (method && methodString) (*env)->ReleaseStringUTFChars(env, method, methodString);
if (signature && sigString) (*env)->ReleaseStringUTFChars(env, signature, sigString);
return result;
NewGlobalRef() returns a new global reference:
callbackData[i].callback = (*env)->NewGlobalRef(env, callbackObject)
If this first global reference succeeds but the second one fails:
callbackData[i].object = (*env)->NewGlobalRef(env, object)
the function jumps to fail. The fail block releases the UTF strings, but it does not delete the already-created callbackData[i].callback global reference and does not clear the partially initialized slot.
This leaves a global reference to the Java Callback object stored in callbackData[i].callback. Since bind() returns 0 on this path, the Java constructor reports callback allocation failure and the normal unbind() path is not reached for this partially initialized entry.
The successful cleanup path does release both global references:
if (callbackData[i].callback != NULL) (*env)->DeleteGlobalRef(env, callbackData[i].callback);
if (callbackData[i].object != NULL) (*env)->DeleteGlobalRef(env, callbackData[i].object);
memset(&callbackData[i], 0, sizeof(CALLBACK_DATA));
but that cleanup is only in CALLBACK_NATIVE(unbind), not in the partial-failure path of bind().
Suggested fix: avoid storing the global references into callbackData[i] until both have been created successfully, or explicitly roll back the first global reference and clear the slot before jumping to fail.
- Ngôn ngữ chính
- Java
- Star
- 202
- Fork
- 206
- Merge trung bình
- 16 giờ 56 phút
- Pull request đã merge (30 ngày)
- 110
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 eclipse-platform/eclipse.platform.swt
-
`SWT_AWT.initFrame` takes `(long, String)` in Java; the GTK native declares no `className` and the Cocoa native types it `const char *`Có thể đã có người làm @GreenFuze đã nhận 3 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
eclipse-platform/eclipse.platform.swt#3665 · 3 bình luận ·
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 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
eclipse-platform/eclipse.platform.swt#3336 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
eclipse-platform/eclipse.platform.swt#3718 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
eclipse-platform/eclipse.platform.swt#3717 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của eclipse-platform/eclipse.platform.swt
Issue tương tự
-
Wrong link to test resultsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
docs(site): Mermaid edge-label contrast on Architecture and a table header on How it comparesĐang mởdocumentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
devops-thiago/ThrillhouseBot#1132 ·
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
carlos-emr/carlos#4732 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày