[PATCH] mqueue: Prevent memory leak by freeing unused node
From: Steven Davis
Date: Thu Sep 19 2024 - 17:41:39 EST
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@xxxxxxxxxxx>
---
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