diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 47ca142c65c6..3c594da1b2c5 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -900,10 +900,12 @@ do_execve(struct thread *td, struct image_args *args, struct mac *mac_p) free(imgp->freepath, M_TEMP); if (error == 0) { - PROC_LOCK(p); - if (p->p_ptevents & PTRACE_EXEC) - td->td_dbgflags |= TDB_EXEC; - PROC_UNLOCK(p); + if (p->p_ptevents & PTRACE_EXEC) { + PROC_LOCK(p); + if (p->p_ptevents & PTRACE_EXEC) + td->td_dbgflags |= TDB_EXEC; + PROC_UNLOCK(p); + } /* * Stop the process here if its stop event mask has