aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSha Zhengju <handai.szj@taobao.com>2012-05-10 13:01:45 -0700
committerBen Hutchings <ben@decadent.org.uk>2012-05-31 00:43:51 +0100
commitb07291bbba3a0ce31a2a35b34b1e3e79c22e4b5b (patch)
treed5af6df60e467ac043eeb55583d74c55b4f4735c
parent2693a093ac93a63749fd595cf4569495014ff1b3 (diff)
memcg: free spare array to avoid memory leak
commit 8c7577637ca31385e92769a77e2ab5b428e8b99c upstream. When the last event is unregistered, there is no need to keep the spare array anymore. So free it to avoid memory leak. Signed-off-by: Sha Zhengju <handai.szj@taobao.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Kirill A. Shutemov <kirill@shutemov.name> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--mm/memcontrol.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 778554ffd63..c8425b144b8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4549,6 +4549,12 @@ static void mem_cgroup_usage_unregister_event(struct cgroup *cgrp,
swap_buffers:
/* Swap primary and spare array */
thresholds->spare = thresholds->primary;
+ /* If all events are unregistered, free the spare array */
+ if (!new) {
+ kfree(thresholds->spare);
+ thresholds->spare = NULL;
+ }
+
rcu_assign_pointer(thresholds->primary, new);
/* To be sure that nobody uses thresholds */