Mikhail Karpov, le jeu. 29 oct. 2026 11:58:46 +0700, a ecrit:
> On Thu, 29 Oct 2026 00:07:46 Samuel Thibault wrote:
>
> > > + err = mach_port_mod_refs (mach_task_self (), transbox->active,
> > > + MACH_PORT_RIGHT_SEND, +1);
> > > + if (err)
> > > + {
> > > + error_t request_err =
> > > + mach_port_request_notification (mach_task_self (),
> > > + transbox->active,
> > > + MACH_NOTIFY_DEAD_NAME, 0,
> > > + MACH_PORT_NULL,
> > > + MACH_MSG_TYPE_MAKE_SEND_ONCE,
> > > + &old);
> > > + assert_perror_backtrace (request_err);
> >
> > I believe you'd have to deallocate the old port.
> >
> > > + goto out;
> > > + }
> > > +
> > > if (MACH_PORT_VALID (old))
> > > mach_port_deallocate (mach_task_self (), old);
> >
> > This also needs to be done anyway, even if err != 0.
>
> I think we could call mach_port_deallocate (mach_task_self (), old)
> immediately after the call to mach_port_request_notification.
> - mach_port_t old;
> - err = mach_port_request_notification (mach_task_self (),
> transbox->active,
> + mach_port_t old = MACH_PORT_NULL;
> + err = mach_port_request_notification (mach_task_self (),
> + transbox->active,
> MACH_NOTIFY_DEAD_NAME, 0,
> pi->port_right,
> MACH_MSG_TYPE_MAKE_SEND_ONCE,
> &old);
> - if (err)
> - goto out;
> if (MACH_PORT_VALID (old))
> mach_port_deallocate (mach_task_self (), old);
No, in case of an error, it's useless to try to deallocate old, we do
know that mach_port_request_notification didn't set a port there.
But we should indeed be able to deallocate 'old' just after checking
that mach_port_request_notification suceeded.
>
> + if (err)
> + goto out;
> +
> + err = mach_port_mod_refs (mach_task_self (), transbox->active,
> + MACH_PORT_RIGHT_SEND, +1);
> + if (err)
> + {
> + old = MACH_PORT_NULL;
> + error_t request_err =
> + mach_port_request_notification (mach_task_self (),
> + transbox->active,
> + MACH_NOTIFY_DEAD_NAME, 0,
> + MACH_PORT_NULL,
Thinking about it, you'd want to restore the old port, to leave the
situation as it was before.
You could call mach_port_mod_refs even before the first
mach_port_request_notification. If it fails, we have nothing to do. Then
we try mach_port_request_notification. If it fails, we just have to
deallocate transbox->active once to undo the mod_refs, and return. If it
succeeds, then we can just finish the rest of the operations and return
success.
Samuel
> + MACH_MSG_TYPE_MAKE_SEND_ONCE,
> + &old);
> + assert_perror_backtrace (request_err);
> + if (MACH_PORT_VALID (old))
> + mach_port_deallocate (mach_task_self (), old);
> +
> + goto out;
> + }
> +
> if (t->pi)
> ports_port_deref (t->pi);
>
> @@ -147,8 +168,7 @@ fshelp_set_active_translator (struct port_info *pi,
>
> if (MACH_PORT_VALID (t->active))
> mach_port_deallocate (mach_task_self (), t->active);
> - mach_port_mod_refs (mach_task_self (), transbox->active,
> - MACH_PORT_RIGHT_SEND, +1);
> +
> t->active = transbox->active;
> }
> else if (! MACH_PORT_VALID (transbox->active))
> --
> 2.43.0
>
--
Samuel
requests.</FONT></SPAN></TD></TR></TBODY></TABLE></DIV></BODY></HTML>agnjo
gj a po mi
shnthdrdcvallus hsx mvgduwolgfwtq
uzuy
s
p
h
-+- spams forever ... -+-