disp = ipc_object_copyin_type(args->polyPoly);
rv = mach_port_insert_right(task->itk_space, args->name, port, disp);
+ if (rv != KERN_SUCCESS) {
+ if (IO_VALID((ipc_object_t)port)) {
+ ipc_object_destroy((ipc_object_t)port, disp);
+ }
+ }
done:
if (task)
if (voucher == IV_NULL)
return MACH_SEND_INVALID_DEST;
- mach_msg_type_number_t __assert_only max_sz = sz;
+ mach_msg_type_number_t max_sz = sz;
if (sz < MACH_VOUCHER_TRAP_STACK_LIMIT) {
/* keep small recipes on the stack for speed */
if (kr == KERN_SUCCESS && sz > 0)
kr = copyout(krecipe, (void *)args->recipe, sz);
} else {
- uint8_t *krecipe = kalloc((vm_size_t)sz);
+ uint8_t *krecipe = kalloc((vm_size_t)max_sz);
if (!krecipe) {
kr = KERN_RESOURCE_SHORTAGE;
goto done;
}
- if (copyin(args->recipe, (void *)krecipe, args->recipe_size)) {
- kfree(krecipe, (vm_size_t)sz);
+ if (copyin(args->recipe, (void *)krecipe, sz)) {
+ kfree(krecipe, (vm_size_t)max_sz);
kr = KERN_MEMORY_ERROR;
goto done;
}
if (kr == KERN_SUCCESS && sz > 0)
kr = copyout(krecipe, (void *)args->recipe, sz);
- kfree(krecipe, (vm_size_t)sz);
+ kfree(krecipe, (vm_size_t)max_sz);
}
kr = copyout(&sz, args->recipe_size, sizeof(sz));