Hello,

On Wed, 30 Sep 2026 00:57:32 Samuel Thibault wrote:

> > diff --git a/proc/mgt.c b/proc/mgt.c
> > index 05af823..b3f7299 100644
> > --- a/proc/mgt.c
> > +++ b/proc/mgt.c
> > @@ -274,7 +274,11 @@ S_proc_child (struct proc *parentp,
> >        childp->end_code = parentp->end_code;
> >      }
> >    if (! childp->exe && parentp->exe)
> > -    childp->exe = strdup (parentp->exe);
> > +    {
> > +      childp->exe = strdup (parentp->exe);
> > +      if (! childp->exe)
> > +        return errno;
> > +    }
>
> Mmm, but we have already deallocated our parameter childt. Returning an
> error here will deallocate it again, leading to missing reference. You
> thus want to duplicate and check it before deallocating childt.

I fixed that part, and now the error returns before the deallocation.

Thanks,

--
Mikhail Karpov
From ee234178952d2aa9851f3a014cb048760ecd01dd Mon Sep 17 00:00:00 2001
From: Mikhail Karpov <[email protected]>
Date: Wed, 30 Sep 2026 11:34:08 +0700
Subject: [PATCH] Fixing strdup in proc/mgt.c

---
 proc/mgt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/proc/mgt.c b/proc/mgt.c
index 05af823f..9ac7fa3e 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -221,6 +221,14 @@ S_proc_child (struct proc *parentp,
   if (childp->p_parentset)
     return EBUSY;
 
+  char *exe_path = NULL;
+  if (parentp->exe)
+    {
+      exe_path = strdup (parentp->exe);
+      if (!exe_path)
+        return errno;
+    }
+
   mach_port_deallocate (mach_task_self (), childt);
 
   /* Process identification.
@@ -273,8 +281,11 @@ S_proc_child (struct proc *parentp,
       childp->start_code = parentp->start_code;
       childp->end_code = parentp->end_code;
     }
+
   if (! childp->exe && parentp->exe)
-    childp->exe = strdup (parentp->exe);
+    childp->exe = exe_path;
+  else if (exe_path)
+    free (exe_path);
 
   if (MACH_PORT_VALID (parentp->p_task_namespace))
     {
-- 
2.43.0

Reply via email to