ffi/unsafe: fix memory-management problem in recent change

Fixes a problem with bba223a9fe.