diff mbox series

target: fix a memory leak in pscsi_map_sg()

Message ID 1541758416-30607-1-git-send-email-mlombard@redhat.com (mailing list archive)
State New, archived
Headers show
Series target: fix a memory leak in pscsi_map_sg() | expand

Commit Message

Maurizio Lombardi Nov. 9, 2018, 10:13 a.m. UTC
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.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
 drivers/target/target_core_pscsi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index 47d76c8..432361e 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -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;
 }