Cycles: Fix Metal use-after-free bug

`entryPoint` was being used unsafely following its release.

Pull Request: https://projects.blender.org/blender/blender/pulls/106572
This commit is contained in:
Michael Jones 2023-04-05 21:50:14 +02:00 committed by Michael Jones (Apple)
parent 92c9c1d400
commit 70edef1311
1 changed files with 2 additions and 6 deletions

View File

@ -445,12 +445,10 @@ void MetalKernelPipeline::compile()
const std::string function_name = std::string("cycles_metal_") +
device_kernel_as_string(device_kernel);
NSString *entryPoint = [@(function_name.c_str()) copy];
NSError *error = NULL;
if (@available(macOS 11.0, *)) {
MTLFunctionDescriptor *func_desc = [MTLIntersectionFunctionDescriptor functionDescriptor];
func_desc.name = entryPoint;
func_desc.name = [@(function_name.c_str()) copy];
if (pso_type != PSO_GENERIC) {
func_desc.constantValues = GetConstantValues(&kernel_data_);
@ -462,8 +460,6 @@ void MetalKernelPipeline::compile()
function = [mtlLibrary newFunctionWithDescriptor:func_desc error:&error];
}
[entryPoint release];
if (function == nil) {
NSString *err = [error localizedDescription];
string errors = [err UTF8String];
@ -471,7 +467,7 @@ void MetalKernelPipeline::compile()
return;
}
function.label = [entryPoint copy];
function.label = [@(function_name.c_str()) copy];
if (use_metalrt) {
if (@available(macOS 11.0, *)) {