Skip to contentSkip to conversation

fs/cifs: Fix resource leak

PATCH New Khaled ROMDHANI 1 participant 1 message May 4, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fs/cifs: Fix resource leak

The -EIO error return path is leaking memory allocated to page. Fix this by moving the allocation block after the check of cifs_forced_shutdown.

Addresses-Coverity: ("Resource leak")

Fixes 087f757b0129 ("cifs: add shutdown support")

---
V2: Add a fix tag and move the allocation to avoid its failure in the declaration block as suggested by Dan Carpenter.
V1: Invoke the free_dentry_path before the return.

---
 fs/cifs/link.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/link.c +5 -1
index 1cbe7ec73728..970fcf2adb08 100644
@@ -683,12 +683,16 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
 	struct tcon_link *tlink;
 	struct cifs_tcon *pTcon;
 	const char *full_path;
-	void *page = alloc_dentry_path();
+	void *page;
 	struct inode *newinode = NULL;
 
 	if (unlikely(cifs_forced_shutdown(cifs_sb)))
 		return -EIO;
 
+	page = alloc_dentry_path();
+	if (!page)
+		return -ENOMEM;
+
 	xid = get_xid();
 
 	tlink = cifs_sb_tlink(cifs_sb);
Signature · 1 line
2.17.1