diff options
-rw-r--r-- | libfshelp/fetch-control.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libfshelp/fetch-control.c b/libfshelp/fetch-control.c index 26c12d88..91c65bb0 100644 --- a/libfshelp/fetch-control.c +++ b/libfshelp/fetch-control.c @@ -19,13 +19,24 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "fshelp.h" +#include <assert.h> error_t fshelp_fetch_control (struct transbox *box, mach_port_t *control) { + error_t err = 0; *control = box->active; if (*control != MACH_PORT_NULL) - mach_port_mod_refs (mach_task_self (), *control, MACH_PORT_RIGHT_SEND, 1); - return 0; + err = mach_port_mod_refs (mach_task_self (), *control, + MACH_PORT_RIGHT_SEND, 1); + + if (err == KERN_INVALID_RIGHT) + { + err = mach_port_deallocate (mach_task_self (), *control); + assert_perror (err); + *control = box->active = MACH_PORT_NULL; + } + + return err; } |