From: Yi Yang Date: Fri, 18 Nov 2022 01:15:34 +0000 (+0900) Subject: rethook: fix a potential memleak in rethook_alloc() X-Git-Tag: v6.1~91^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a1ebe35cb3b7aa1f4b26b37e2a0b9ae68dc4ffb;p=platform%2Fkernel%2Flinux-starfive.git rethook: fix a potential memleak in rethook_alloc() In rethook_alloc(), the variable rh is not freed or passed out if handler is NULL, which could lead to a memleak, fix it. Link: https://lore.kernel.org/all/20221110104438.88099-1-yiyang13@huawei.com/ [Masami: Add "rethook:" tag to the title.] Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook") Cc: stable@vger.kernel.org Signed-off-by: Yi Yang Acke-by: Masami Hiramatsu (Google) Signed-off-by: Masami Hiramatsu (Google) --- diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c index c69d822..32c3dfd 100644 --- a/kernel/trace/rethook.c +++ b/kernel/trace/rethook.c @@ -83,8 +83,10 @@ struct rethook *rethook_alloc(void *data, rethook_handler_t handler) { struct rethook *rh = kzalloc(sizeof(struct rethook), GFP_KERNEL); - if (!rh || !handler) + if (!rh || !handler) { + kfree(rh); return NULL; + } rh->data = data; rh->handler = handler;