public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mmotm 2/2] cpuset: alloc nodemask_t at heap not stack - fix
@ 2010-03-12  6:59 Miao Xie
  2010-03-12  9:45 ` David Rientjes
  0 siblings, 1 reply; 2+ messages in thread
From: Miao Xie @ 2010-03-12  6:59 UTC (permalink / raw)
  To: Andrew Morton, David Rientjes, Paul Menage, Linux-Kernel

fix memory leak

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
Against the following patch in mmotm-2010-03-11-13-13:
cpuset-alloc-nodemask_t-at-heap-not-stack.patch
---
 kernel/cpuset.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index f36e577..8e27d00 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -1401,7 +1401,7 @@ static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
 	NODEMASK_ALLOC(nodemask_t, to, GFP_KERNEL);
 
 	if (from == NULL || to == NULL)
-		return;
+		goto alloc_fail;
 
 	if (cs == &top_cpuset) {
 		cpumask_copy(cpus_attach, cpu_possible_mask);
@@ -1432,8 +1432,12 @@ static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
 		mmput(mm);
 	}
 
-	NODEMASK_FREE(from);
-	NODEMASK_FREE(to);
+alloc_fail:
+	if (from)
+		NODEMASK_FREE(from);
+
+	if (to)
+		NODEMASK_FREE(to);
 }
 
 /* The various types of files and directories in a cpuset file system */
-- 
1.6.5.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -mmotm 2/2] cpuset: alloc nodemask_t at heap not stack - fix
  2010-03-12  6:59 [PATCH -mmotm 2/2] cpuset: alloc nodemask_t at heap not stack - fix Miao Xie
@ 2010-03-12  9:45 ` David Rientjes
  0 siblings, 0 replies; 2+ messages in thread
From: David Rientjes @ 2010-03-12  9:45 UTC (permalink / raw)
  To: Miao Xie; +Cc: Andrew Morton, Paul Menage, Linux-Kernel

On Fri, 12 Mar 2010, Miao Xie wrote:

> fix memory leak
> 
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
> Against the following patch in mmotm-2010-03-11-13-13:
> cpuset-alloc-nodemask_t-at-heap-not-stack.patch
> ---
>  kernel/cpuset.c |   10 +++++++---
>  1 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/cpuset.c b/kernel/cpuset.c
> index f36e577..8e27d00 100644
> --- a/kernel/cpuset.c
> +++ b/kernel/cpuset.c
> @@ -1401,7 +1401,7 @@ static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
>  	NODEMASK_ALLOC(nodemask_t, to, GFP_KERNEL);
>  
>  	if (from == NULL || to == NULL)
> -		return;
> +		goto alloc_fail;
>  
>  	if (cs == &top_cpuset) {
>  		cpumask_copy(cpus_attach, cpu_possible_mask);
> @@ -1432,8 +1432,12 @@ static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont,
>  		mmput(mm);
>  	}
>  
> -	NODEMASK_FREE(from);
> -	NODEMASK_FREE(to);
> +alloc_fail:
> +	if (from)
> +		NODEMASK_FREE(from);
> +
> +	if (to)
> +		NODEMASK_FREE(to);

kfree() can take NULL pointers.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-12  9:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-12  6:59 [PATCH -mmotm 2/2] cpuset: alloc nodemask_t at heap not stack - fix Miao Xie
2010-03-12  9:45 ` David Rientjes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox