Fixed issue with not properly closing C++ models in some circumstances.