ffi: segfault when a signature getter closes the library in getFunction()
Author: trivikrCreated Sep 28, 2026Updated Sep 28, 2026
Labelsffi
Version
main
Platform
macOS 26.7.0Subsystem
ffi
What steps will reproduce the bug?
import { DynamicLibrary } from 'node:ffi';
const lib = new DynamicLibrary(process.argv[2]);
lib.getFunction('add_i32', { arguments: ['i32', 'i32'], return: 'i32' });
lib.getFunction('add_i32', {
arguments: ['i32', 'i32'],
get return() { lib.close(); return 'i32'; },
});Run with node repro.js, using any shared library that exports add_i32 (for example, test/ffi/fixture_library)
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The second call should throw ERR_FFI_LIBRARY_CLOSED, the same error getFunction() throws on a closed library.
What do you see instead?
The process crashes with a segmentation fault (exit code 139).
Additional information
No response
Source: nodejs/node