[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210401075531.GA2766105@LEGION>
Date: Thu, 1 Apr 2021 12:55:31 +0500
From: Muhammad Usama Anjum <musamaanjum@...il.com>
To: Namjae Jeon <namjae.jeon@...sung.com>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
Steve French <sfrench@...ba.org>,
Hyunchul Lee <hyc.lee@...il.com>,
"open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)"
<linux-cifs@...r.kernel.org>,
"open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)"
<linux-cifsd-devel@...ts.sourceforge.net>,
open list <linux-kernel@...r.kernel.org>,
kernel-janitors@...r.kernel.org, colin.king@...onical.com,
dan.carpenter@...cle.com
Cc: musamaanjum@...il.com
Subject: [PATCH] cifsd: fix memory leak when loop ends
Memory is being allocated and if veto_list is zero, the loop breaks
without cleaning up the allocated memory. In this patch, the length
check has been moved before allocation. If loop breaks, the memory isn't
allocated in the first place. Thus the memory is being protected from
leaking.
Signed-off-by: Muhammad Usama Anjum <musamaanjum@...il.com>
---
fs/cifsd/mgmt/share_config.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fs/cifsd/mgmt/share_config.c b/fs/cifsd/mgmt/share_config.c
index db780febd692..b2bd789af945 100644
--- a/fs/cifsd/mgmt/share_config.c
+++ b/fs/cifsd/mgmt/share_config.c
@@ -92,14 +92,14 @@ static int parse_veto_list(struct ksmbd_share_config *share,
while (veto_list_sz > 0) {
struct ksmbd_veto_pattern *p;
- p = kzalloc(sizeof(struct ksmbd_veto_pattern), GFP_KERNEL);
- if (!p)
- return -ENOMEM;
-
sz = strlen(veto_list);
if (!sz)
break;
+ p = kzalloc(sizeof(struct ksmbd_veto_pattern), GFP_KERNEL);
+ if (!p)
+ return -ENOMEM;
+
p->pattern = kstrdup(veto_list, GFP_KERNEL);
if (!p->pattern) {
ksmbd_free(p);
--
2.25.1
Powered by blists - more mailing lists