exec: fix potential deadlock after fork()