Hello,

Mikhail Karpov, le mer. 30 sept. 2026 11:40:24 +0700, a ecrit:
> 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);

Better only strdup if !childp->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);

That'll avoid having to allocate/free it for nothing.

Samuel

Reply via email to