[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGFP0L+BaNAtCF7c7cJ1bvbjomp03Fy0=6=w6dj29Fnr0ygSCA@mail.gmail.com>
Date: Mon, 3 Jun 2024 21:33:19 +0900
From: Geunsik Lim <geunsik.lim@...il.com>
To: Axel Rasmussen <axelrasmussen@...gle.com>, Vlastimil Babka <vbabka@...e.cz>,
Ingo Molnar <mingo@...e.hu>, Andrew Morton <akpm@...ux-foundation.org>,
Thomas Gleixner <tglx@...utronix.de>, Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Hugh Dickins <hughd@...gle.com>
Cc: "H. Peter Anvin" <hpa@...or.com>, Steven Rostedt <rostedt@...dmis.org>,
linux-kernel <linux-kernel@...r.kernel.org>, linux-mm <linux-mm@...ck.org>
Subject: [PATCH] fix: Prevent memory leak by checking for NULL buffer before
calling css_put()
This commit addresses a potential memory leak in the
`get_mm_memcg_path()` function
by explicitly checking if the allocated buffer (`buf`) is NULL before
calling the
`css_put()` function. The prefix 'css' means abbreviation of cgroup_subsys_state
Previously, the code would directly call `css_put()` without checking
the value of
`buf`, which could lead to a memory leak if the buffer allocation failed.
This commit introduces a conditional check to ensure that `css_put()`
is only called
if `buf` is not NULL.
This change enhances the code's robustness and prevents memory leaks, improving
overall system stability.
**Specific Changes:**
* In the `out_put` label, an `if` statement is added to check
if `buf` is not NULL before calling `css_put()`.
**Benefits:**
* Prevents potential memory leaks
* Enhances code robustness
* Improves system stability
Signed-off-by: Geunsik Lim <leemgs@...il.com>
Signed-off-by: Geunsik Lim <geunsik.lim@...sung.com>
---
mm/mmap_lock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
index 1854850b4b89..7314045b0e3b 100644
--- a/mm/mmap_lock.c
+++ b/mm/mmap_lock.c
@@ -213,7 +213,8 @@ static const char *get_mm_memcg_path(struct mm_struct *mm)
cgroup_path(memcg->css.cgroup, buf, MEMCG_PATH_BUF_SIZE);
out_put:
- css_put(&memcg->css);
+ if (buf != NULL)
+ css_put(&memcg->css);
out:
return buf;
}
--
2.34.1
----
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists