From: Muhammad Usama Anjum Date: Thu, 1 Apr 2021 08:54:43 +0000 (+0900) Subject: cifsd: fix memory leak when loop ends X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c250e8f5566f2e1a0ea177837520eff8e59c0b7d;p=linux.git 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. Reported-by: coverity-bot Addresses-Coverity-ID: 1503590 ("Resource leaks") Signed-off-by: Muhammad Usama Anjum Signed-off-by: Namjae Jeon Signed-off-by: Steve French --- diff --git a/fs/cifsd/mgmt/share_config.c b/fs/cifsd/mgmt/share_config.c index db780febd692a..b2bd789af945f 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);