Skip to contentSkip to conversation

target: fix potential memory leak in option parsing

PATCH New Chengguang Xu 1 participant 1 message Apr 17, 2018 SCSI target

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: fix potential memory leak in option parsing

When specifying same string type option several times, current option parsing will cause memory leak. Hence, call kfree for previous one in this case.

---
 drivers/target/target_core_configfs.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/target/target_core_configfs.c +5 -0
index 3f4bf12..ee1a3a8 100644
@@ -1659,6 +1659,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item,
 		token = match_token(ptr, tokens, args);
 		switch (token) {
 		case Opt_initiator_fabric:
+			kfree(i_fabric);
 			i_fabric = match_strdup(args);
 			if (!i_fabric) {
 				ret = -ENOMEM;
@@ -1666,6 +1667,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item,
 			}
 			break;
 		case Opt_initiator_node:
+			kfree(i_port);
 			i_port = match_strdup(args);
 			if (!i_port) {
 				ret = -ENOMEM;
@@ -1680,6 +1682,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item,
 			}
 			break;
 		case Opt_initiator_sid:
+			kfree(isid);
 			isid = match_strdup(args);
 			if (!isid) {
 				ret = -ENOMEM;
@@ -1737,6 +1740,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item,
 		 * PR APTPL Metadata for Target Port
 		 */
 		case Opt_target_fabric:
+			kfree(t_fabric);
 			t_fabric = match_strdup(args);
 			if (!t_fabric) {
 				ret = -ENOMEM;
@@ -1744,6 +1748,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item,
 			}
 			break;
 		case Opt_target_node:
+			kfree(t_port);
 			t_port = match_strdup(args);
 			if (!t_port) {
 				ret = -ENOMEM;
Signature · 1 line
1.8.3.1