linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Muhammad Usama Anjum <musamaanjum@gmail.com>
To: Namjae Jeon <namjae.jeon@samsung.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steve French <sfrench@samba.org>,
	Hyunchul Lee <hyc.lee@gmail.com>,
	"open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)" 
	<linux-cifs@vger.kernel.org>,
	"open list:COMMON INTERNET FILE SYSTEM SERVER (CIFSD)" 
	<linux-cifsd-devel@lists.sourceforge.net>,
	open list <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org, colin.king@canonical.com,
	dan.carpenter@oracle.com
Cc: musamaanjum@gmail.com
Subject: [PATCH] cifsd: fix memory leak when loop ends
Date: Thu, 1 Apr 2021 12:55:31 +0500	[thread overview]
Message-ID: <20210401075531.GA2766105@LEGION> (raw)

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@gmail.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


             reply	other threads:[~2021-04-01  7:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210401075539epcas1p3b7cb52923217b212c80185aab135fe22@epcas1p3.samsung.com>
2021-04-01  7:55 ` Muhammad Usama Anjum [this message]
2021-04-01  8:17   ` [PATCH] cifsd: fix memory leak when loop ends Namjae Jeon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210401075531.GA2766105@LEGION \
    --to=musamaanjum@gmail.com \
    --cc=colin.king@canonical.com \
    --cc=dan.carpenter@oracle.com \
    --cc=hyc.lee@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-cifsd-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namjae.jeon@samsung.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=sfrench@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).