浏览代码

[PATCH] selinux: fix memory leak

This patch fixes a memory leak when a policydb structure is destroyed.

Signed-off-by: Darrel Goeddel <dgoeddel@trustedcs.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Darrel Goeddel 19 年之前
父节点
当前提交
ddccef3b5e
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      security/selinux/ss/policydb.c

+ 10 - 2
security/selinux/ss/policydb.c

@@ -644,10 +644,18 @@ void policydb_destroy(struct policydb *p)
 	kfree(lra);
 	kfree(lra);
 
 
 	for (rt = p->range_tr; rt; rt = rt -> next) {
 	for (rt = p->range_tr; rt; rt = rt -> next) {
-		kfree(lrt);
+		if (lrt) {
+			ebitmap_destroy(&lrt->range.level[0].cat);
+			ebitmap_destroy(&lrt->range.level[1].cat);
+			kfree(lrt);
+		}
 		lrt = rt;
 		lrt = rt;
 	}
 	}
-	kfree(lrt);
+	if (lrt) {
+		ebitmap_destroy(&lrt->range.level[0].cat);
+		ebitmap_destroy(&lrt->range.level[1].cat);
+		kfree(lrt);
+	}
 
 
 	if (p->type_attr_map) {
 	if (p->type_attr_map) {
 		for (i = 0; i < p->p_types.nprim; i++)
 		for (i = 0; i < p->p_types.nprim; i++)