Fix some errors with the native-function refcounting.