Hello,
This is a small patch that adds a NULL check for childp in proc/mgt.c.
I’m not entirely certain, but perhaps it would be better not to return the
result from mach_notify_new_task immediately; instead, one should first
check
for an error, and if one exists, dealloc the task and call deref on childp.
Thanks,
--
Mikhail Karpov
From b12bbcd88f26527e401d57d9c10f4488a0875f6a Mon Sep 17 00:00:00 2001
From: Mikhail Karpov <[email protected]>
Date: Sun, 1 Nov 2026 13:58:51 +0700
Subject: [PATCH 3/5] Added a NULL check for childp in proc/mgt.c
---
proc/mgt.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/proc/mgt.c b/proc/mgt.c
index c898d0d..4134943 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -829,7 +829,10 @@ allocate_proc (task_t task)
err = ports_create_port (proc_class, proc_bucket, sizeof (struct proc), &p);
if (err)
- return NULL;
+ {
+ errno = err;
+ return NULL;
+ }
memset (&p->p_pi + 1, 0, sizeof *p - sizeof p->p_pi);
p->p_task = task;
@@ -1412,6 +1415,13 @@ S_mach_notify_new_task (struct port_info *notify,
return err;
childp = new_proc (task);
+ if (! childp)
+ {
+ err = errno;
+ mach_port_deallocate (mach_task_self (), task);
+ return err;
+ }
+
needs_task_dealloc = 1;
}
@@ -1424,7 +1434,10 @@ S_mach_notify_new_task (struct port_info *notify,
if (err)
{
if (needs_task_dealloc)
- mach_port_deallocate (mach_task_self (), task);
+ {
+ ports_port_deref (childp);
+ mach_port_deallocate (mach_task_self (), task);
+ }
return err;
}
--
2.43.0