[<prev] [next>] [day] [month] [year] [list]
Message-ID:
<SJ2P223MB10262FC2C833475F2A5BEE3EF7632@SJ2P223MB1026.NAMP223.PROD.OUTLOOK.COM>
Date: Thu, 19 Sep 2024 17:40:58 -0400
From: Steven Davis <goldside000@...look.com>
To: brauner@...nel.org
Cc: jlayton@...nel.org,
nichen@...as.ac.cn,
linux-kernel@...r.kernel.org,
Steven Davis <goldside000@...look.com>
Subject: [PATCH] mqueue: Prevent memory leak by freeing unused node
Added a check to free the newly allocated node when the node cache is NULL.
This prevents memory leaks by ensuring that memory allocated with kmalloc
is released if it is not being reused from the cache. This change enhances
memory management consistency within the msg_insert function.
Signed-off-by: Steven Davis <goldside000@...look.com>
---
ipc/mqueue.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index a7cbd69efbef..59ec6b3c1557 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -227,6 +227,10 @@ static int msg_insert(struct msg_msg *msg, struct mqueue_inode_info *info)
info->attr.mq_curmsgs++;
info->qsize += msg->m_ts;
list_add_tail(&msg->m_list, &leaf->msg_list);
+
+ if (info->node_cache == NULL)
+ kfree(leaf);
+
return 0;
}
--
2.39.5
Powered by blists - more mailing lists