Skip to contentSkip to conversation

9p: check memory allocation result for cachetag

PATCH New Chengguang Xu 1 participant 1 message Mar 21, 2018 9P file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 9p: check memory allocation result for cachetag

Check memory allocation result for cachetag in mount option parsing and fix potential memory leak in the error case.

---
 fs/9p/v9fs.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/9p/v9fs.c +7 -0
index 8fb89dd..e622f0f 100644
@@ -292,6 +292,10 @@ static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
 #ifdef CONFIG_9P_FSCACHE
 			kfree(v9ses->cachetag);
 			v9ses->cachetag = match_strdup(&args[0]);
+			if (!v9ses->cachetag) {
+				ret = -ENOMEM;
+				goto free_and_return;
+			}
 #endif
 			break;
 		case Opt_cache:
@@ -471,6 +475,9 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
 	return fid;
 
 err_clnt:
+#ifdef CONFIG_9P_FSCACHE
+	kfree(v9ses->cachetag);
+#endif
 	p9_client_destroy(v9ses->clnt);
 err_names:
 	kfree(v9ses->uname);
Signature · 1 line
1.8.3.1