Blob Blame History Raw
From 7b5f3e98680f0720f9e6d06b6acdcbf92af4aedd Mon Sep 17 00:00:00 2001
From: Pingfan Liu <piliu@redhat.com>
Date: Thu, 10 Jun 2021 10:54:08 +0800
Subject: [PATCH 2/6] shm.c: fix memleak in dump_shm()

Signed-off-by: Pingfan Liu <piliu@redhat.com>
---
 shm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/shm.c b/shm.c
index 79043c9..c0b6ee3 100644
--- a/shm.c
+++ b/shm.c
@@ -182,7 +182,7 @@ dumppol(unsigned long long start, unsigned long long end, int pol, struct bitmas
 /* Dump policies in a shared memory segment. */
 void dump_shm(void)
 {
-	struct bitmask *nodes, *prevnodes;
+	struct bitmask *nodes, *prevnodes, *tag;
 	int prevpol = -1, pol;
 	unsigned long long c, start;
 
@@ -193,7 +193,7 @@ void dump_shm(void)
 	}
 
 	nodes = numa_allocate_nodemask();
-	prevnodes = numa_allocate_nodemask();
+	tag = prevnodes = numa_allocate_nodemask();
 
 	for (c = 0; c < shmlen; c += shm_pagesize) {
 		if (get_mempolicy(&pol, nodes->maskp, nodes->size, c+shmptr,
@@ -208,6 +208,8 @@ void dump_shm(void)
 		start = c;
 	}
 	dumppol(start, c, prevpol, prevnodes);
+	numa_free_nodemask(nodes);
+	numa_free_nodemask(tag);
 }
 
 static void dumpnode(unsigned long long start, unsigned long long end, int node)
-- 
2.29.2