diff --git a/CHANGES.md b/CHANGES.md index dca66650de..87916bb617 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ Features Bug Fixes --------- +* [#TBD](https://github.com/java-native-access/jna/pull/TBD): Handle failure in `ffi_closure_alloc` - [@davecturner](https://github.com/davecturner). Release 5.9.0 diff --git a/native/dispatch.c b/native/dispatch.c index f87c572b9e..949856bcba 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -3466,6 +3466,11 @@ Java_com_sun_jna_Native_registerMethod(JNIEnv *env, jclass UNUSED(ncls), } closure = ffi_closure_alloc(sizeof(ffi_closure), &code); + if (closure == NULL) { + throwByName(env, EUnsupportedOperation, "Failed to allocate closure"); + status = FFI_BAD_ABI; + goto cleanup; + } status = ffi_prep_closure_loc(closure, closure_cif, dispatch_direct, data, code); if (status != FFI_OK) { throwByName(env, EError, "Native method linkage failed");