Skip to contentSkip to conversation

target: fix a memory leak in pscsi_map_sg()

PATCH New Maurizio Lombardi 1 participant 1 message Nov 9, 2018 SCSI target

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: fix a memory leak in pscsi_map_sg()

If blk_rq_append_bio() fails, the bio should be released before returning. This patch also removes a "bio = NULL" assignment which is not needed because the bio pointer will be immediatly reassigned after the jump.

---
 drivers/target/target_core_pscsi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/target/target_core_pscsi.c +2 -5
index 47d76c8..432361e 100644
@@ -948,11 +948,6 @@ static inline struct bio *pscsi_get_bio(int nr_vecs)
 					goto fail;
 				}
 
-				/*
-				 * Clear the pointer so that another bio will
-				 * be allocated with pscsi_get_bio() above.
-				 */
-				bio = NULL;
 				goto new_bio;
 			}
 
@@ -970,6 +965,8 @@ static inline struct bio *pscsi_get_bio(int nr_vecs)
 
 	return 0;
 fail:
+	if (bio)
+		bio_put(bio);
 	return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 }
 
Signature · 1 line
Maurizio Lombardi