[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231118113357.1999-1-kamil.duljas@gmail.com>
Date: Sat, 18 Nov 2023 12:33:57 +0100
From: Kamil Duljas <kamil.duljas@...il.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: "David S . Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Jiri Pirko <jiri@...nulli.us>,
Johannes Berg <johannes@...solutions.net>,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
Kamil Duljas <kamil.duljas@...il.com>
Subject: [PATCH] genetlink: Prevent memory leak when krealloc fail
genl_allocate_reserve_groups() allocs new memory in while loop
but if krealloc fail, the memory allocated by kzalloc is not freed.
It seems allocated memory is unnecessary when the function
returns -ENOMEM
Signed-off-by: Kamil Duljas <kamil.duljas@...il.com>
---
net/netlink/genetlink.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 92ef5ed2e7b0..82273d6eaea3 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -437,8 +437,10 @@ static int genl_allocate_reserve_groups(int n_groups, int *first_id)
} else {
new_groups = krealloc(mc_groups, nlen,
GFP_KERNEL);
- if (!new_groups)
+ if (!new_groups) {
+ kfree(mc_groups);
return -ENOMEM;
+ }
mc_groups = new_groups;
for (i = 0; i < BITS_TO_LONGS(n_groups); i++)
mc_groups[mc_groups_longs + i] = 0;
--
2.42.0.windows.2
Powered by blists - more mailing lists