Fix issue with NIF resource allocation

Thanks RGafiyatullin for the fix