From abc025016be6ff65e3a742389369ad62938d6065 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Wed, 1 Mar 2017 14:43:44 +0300 Subject: [PATCH] sk-queue: dump_sk_creds -- Don't leak memory for SkUcredEntry When error happened in dump_sk_creds or dumping in dump_sk_queue passed fine we can leak xmalloc'ed SkUcredEntry. Fix it. Note it's not critical anyhow since CRIU will end up execution in both cases and OS release memory automatically but still. Signed-off-by: Cyrill Gorcunov (cherry picked from commit 969a2aba0331ff940501205077766859453b9a35) Signed-off-by: Alexander Mikhalitsyn --- criu/sk-queue.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/criu/sk-queue.c b/criu/sk-queue.c index ae19bbc20..985459fb8 100644 --- a/criu/sk-queue.c +++ b/criu/sk-queue.c @@ -153,7 +153,7 @@ static int dump_sk_creds(struct ucred *ucred, SkPacketEntry *pe, int flags) * because virt pid-s are known for dumped task only */ pr_err("ucred-s for unix sockets aren't supported yet\n"); - return -1; + goto out; } else { int pidns = root_ns_mask & CLONE_NEWPID; char path[64]; @@ -171,13 +171,17 @@ static int dump_sk_creds(struct ucred *ucred, SkPacketEntry *pe, int flags) } if (ret) { pr_err("Unable to dump ucred for a dead process %d\n", ucred->pid); - return -1; + goto out; } ent->pid = ucred->pid; } + pe->ucred = ent; return 0; +out: + xfree(ent); + return -1; } static int dump_packet_cmsg(struct msghdr *mh, SkPacketEntry *pe, int flags) @@ -361,6 +365,7 @@ err_set_sock: if (pe.scm) release_cmsg(&pe); err_brk: + xfree(pe.ucred); xfree(data); return ret; }