Skip to contentSkip to conversation

target: Fix memory leak on error path

PATCH In review Roland Dreier 2 participants 2 messages Jan 16, 2011

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

PATCH 1/1 target: Fix memory leak on error path

If allocation of pt->pscsi_cdb fails, we need to free the just-allocated pt or else it will be leaked.

---
 drivers/target/target_core_pscsi.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/target/target_core_pscsi.c +1 -0
index 742d246..60a2509 100644
@@ -817,6 +817,7 @@ pscsi_alloc_task(struct se_cmd *cmd)
 		if (!(pt->pscsi_cdb)) {
 			printk(KERN_ERR "pSCSI: Unable to allocate extended"
 					" pt->pscsi_cdb\n");
+			kfree(pt);
 			return NULL;
 		}
 	} else
#1 lore raw
Quoted 4 lines · Roland Dreier

If allocation of pt->pscsi_cdb fails, we need to free the just-allocated pt or else it will be leaked.

Good catch here. Committed as dea3bdb0081 and pushed into lio-core-2.6.git/linus-38-rc1 and scsi-post-merge-2.6.git/for-jejb.

Thanks Roland!

--nab

Quoted 21 lines
---
 drivers/target/target_core_pscsi.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/target/target_core_pscsi.c +1 -1
index 742d246..60a2509 100644
@@ -817,6 +817,7 @@ pscsi_alloc_task(struct se_cmd *cmd)
 		if (!(pt->pscsi_cdb)) {
 			printk(KERN_ERR "pSCSI: Unable to allocate extended"
 					" pt->pscsi_cdb\n");
+			kfree(pt);
 			return NULL;
 		}
 	} else
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/