From 40ae0fa35a8d9268a9559f5d479fa002a1f79697 Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Sat, 6 Dec 2014 23:25:00 +0300 Subject: [PATCH] criu: check: don't leak the child if PTRACE_ATTACH fails PS: never ever use PTRACE_KILL. Signed-off-by: Oleg Nesterov Signed-off-by: Pavel Emelyanov --- cr-check.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cr-check.c b/cr-check.c index f384bdfec..d144e6147 100644 --- a/cr-check.c +++ b/cr-check.c @@ -548,8 +548,11 @@ static int check_ptrace_peeksiginfo() exit(1); } - if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) - return -1; + if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) { + pr_perror("Unable to ptrace the child"); + ret = -1; + goto out; + } waitpid(pid, NULL, 0); @@ -567,8 +570,8 @@ static int check_ptrace_peeksiginfo() ret = -1; } - ptrace(PTRACE_KILL, pid, NULL, NULL); - +out: + kill(pid, SIGKILL); return ret; }