summaryrefslogtreecommitdiff
path: root/libports
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2013-11-30 17:20:12 +0100
committerRichard Braun <rbraun@sceen.net>2013-11-30 17:20:12 +0100
commite5bb7f10e01224d75e55da6e545f779ac0fa73a3 (patch)
treeebf486b526e19c914b3e2f6ea9f17848daa07d53 /libports
parent34ff01a84390ba7a5c0377c326944fc026d66140 (diff)
libports: another right leak fix
* libports/manage-multithread.c (adjust_priority): Deallocate host right before returning.
Diffstat (limited to 'libports')
-rw-r--r--libports/manage-multithread.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c
index be080304..dcebd097 100644
--- a/libports/manage-multithread.c
+++ b/libports/manage-multithread.c
@@ -53,36 +53,43 @@ adjust_priority (unsigned int totalthreads)
t = 10 + (((totalthreads - 1) / 100) + 1) * 10;
thread_switch (MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, t);
- self = pset = pset_priv = MACH_PORT_NULL;
-
err = get_privileged_ports (&host_priv, NULL);
if (err)
- goto out;
+ goto error_host_priv;
self = mach_thread_self ();
err = thread_get_assignment (self, &pset);
if (err)
- goto out;
+ goto error_pset;
err = host_processor_set_priv (host_priv, pset, &pset_priv);
if (err)
- goto out;
+ goto error_pset_priv;
err = thread_max_priority (self, pset_priv, 0);
if (err)
- goto out;
+ goto error_max_priority;
err = thread_priority (self, THREAD_PRI, 0);
-
-out:
- if (self != MACH_PORT_NULL)
- mach_port_deallocate (mach_task_self (), self);
- if (pset != MACH_PORT_NULL)
- mach_port_deallocate (mach_task_self (), pset);
- if (pset_priv != MACH_PORT_NULL)
- mach_port_deallocate (mach_task_self (), pset_priv);
-
- if (err && err != EPERM)
+ if (err)
+ goto error_priority;
+
+ mach_port_deallocate (mach_task_self (), pset_priv);
+ mach_port_deallocate (mach_task_self (), pset);
+ mach_port_deallocate (mach_task_self (), self);
+ mach_port_deallocate (mach_task_self (), host_priv);
+ return;
+
+error_priority:
+error_max_priority:
+ mach_port_deallocate (mach_task_self (), pset_priv);
+error_pset_priv:
+ mach_port_deallocate (mach_task_self (), pset);
+error_pset:
+ mach_port_deallocate (mach_task_self (), self);
+ mach_port_deallocate (mach_task_self (), host_priv);
+error_host_priv:
+ if (err != EPERM)
error (0, err, "unable to adjust libports thread priority");
}