Skip to contentSkip to conversation

cpuset: alloc nodemask_t at heap not stack - fix

PATCH Superseded Miao Xie 2 participants 2 messages Mar 12, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Miao Xie

author
#0 lore raw

PATCH 2/2 cpuset: alloc nodemask_t at heap not stack - fix

fix memory leak

---
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(-)
kernel/cpuset.c +7 -3
index f36e577..8e27d00 100644
@@ -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 */
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 25 lines · Miao Xie

fix memory leak

---
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(-)
kernel/cpuset.c +1 -1
index f36e577..8e27d00 100644
@@ -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);

kernel/cpuset.c static void cpuset_attach(struct cgroup_subsys *ss, struct cgroup *cont, · line 1440

Quoted 10 lines
kernel/cpuset.c +6 -2
 	}
 
-	NODEMASK_FREE(from);
-	NODEMASK_FREE(to);
+alloc_fail:
+	if (from)
+		NODEMASK_FREE(from);
+
+	if (to)
+		NODEMASK_FREE(to);

kfree() can take NULL pointers.