public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: wzt <wzt.wzt@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: serue@us.ibm.com, xemul@openvz.org, ebiederm@xmission.com
Subject: [PATCH] kernel/nsproxy.c: Fix memory leak of create_new_namespaces().
Date: Tue, 18 Oct 2011 12:20:07 +0800	[thread overview]
Message-ID: <20111018042007.GA7222@program> (raw)

copy_pid_ns() has allocted some memory via create_pid_namespace(), if copy_net_ns()
failed via create_new_namespaces(), it will cause memory leak. The copy_utsname() 
have the same problem.

Signed-off-by: Zhitong Wang <zhitong.wangzt@alibaba-inc.com>

---
 kernel/nsproxy.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 9aeab4b..e2d18c9 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -99,14 +99,18 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
 	return new_nsp;
 
 out_net:
-	if (new_nsp->pid_ns)
+	if (new_nsp->pid_ns) {
 		put_pid_ns(new_nsp->pid_ns);
+		free_pid_ns(&new_nsp->pid_ns->kfre);
+	}
 out_pid:
 	if (new_nsp->ipc_ns)
 		put_ipc_ns(new_nsp->ipc_ns);
 out_ipc:
-	if (new_nsp->uts_ns)
+	if (new_nsp->uts_ns) {
 		put_uts_ns(new_nsp->uts_ns);
+		free_uts_ns(&new_nsp->pid_ns->kfref);
+	}
 out_uts:
 	if (new_nsp->mnt_ns)
 		put_mnt_ns(new_nsp->mnt_ns);
-- 
1.7.4.1


             reply	other threads:[~2011-10-18  4:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-18  4:20 wzt [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-10-18  6:07 [PATCH] kernel/nsproxy.c: Fix memory leak of create_new_namespaces() wzt
     [not found] ` <CAJn8CcFded9JCh+G=dQJtjkWGrg-qXbJu2U66TX=r4PVpjQNSA@mail.gmail.com>
2011-10-18  7:19   ` wzt wzt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111018042007.GA7222@program \
    --to=wzt.wzt@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serue@us.ibm.com \
    --cc=xemul@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox