kk: Remove mem leaks in NIR->MSL, device/sampler create and cmdbuf release

Reviewed-by: Arcady Goldmints-Orlov <arcady@lunarg.com>
Signed-off-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38596>
This commit is contained in:
Aitor Camacho 2025-11-23 22:29:30 +09:00 committed by Marge Bot
parent 7eae8bee52
commit a015397c52
4 changed files with 12 additions and 7 deletions

View file

@ -38,8 +38,10 @@ mtl_add_completed_handler(mtl_command_buffer *cmd, void (*callback)(void *data),
@autoreleasepool {
id<MTLCommandBuffer> mtl_cmd = (id<MTLCommandBuffer>)cmd;
[mtl_cmd addCompletedHandler:^(id<MTLCommandBuffer> _Nonnull cmd_buf) {
if (callback)
callback(data);
@autoreleasepool {
if (callback)
callback(data);
}
}];
}
}

View file

@ -20,20 +20,20 @@ mtl_device_create()
mtl_device *device = 0u;
@autoreleasepool {
NSArray<id<MTLDevice>> *devs = MTLCopyAllDevices();
NSArray<id<MTLDevice>> *devs = [MTLCopyAllDevices() autorelease];
uint32_t device_count = [devs count];
for (uint32_t i = 0u; i < device_count; ++i) {
if (@available(macOS 10.15, *)) {
if (!device && [devs[i] supportsFamily:MTLGPUFamilyMetal3]) {
device = (mtl_device *)[devs[i] retain];
break;
}
[devs[i] autorelease];
}
}
return device;
}
return device;
}
/* Device operations */

View file

@ -2034,6 +2034,7 @@ nir_to_msl(nir_shader *shader, void *mem_ctx, uint64_t disabled_workarounds)
ctx.indentlevel--;
P(&ctx, "}\n");
char *ret = ctx.text->buf;
_mesa_hash_table_destroy(ctx.types, NULL);
ralloc_steal(mem_ctx, ctx.text->buf);
ralloc_free(ctx.text);
return ret;

View file

@ -126,7 +126,9 @@ kk_sampler_create(struct kk_device *dev,
const struct mtl_sampler_packed *packed)
{
mtl_sampler_descriptor *desc = create_sampler_descriptor(packed);
return mtl_new_sampler(dev->mtl_handle, desc);
mtl_sampler *sampler = mtl_new_sampler(dev->mtl_handle, desc);
mtl_release(desc);
return sampler;
}
VKAPI_ATTR VkResult VKAPI_CALL