From 97d2f681d7d434b166114a031fb3eb4aec97affd Mon Sep 17 00:00:00 2001 From: Li Feng Date: Fri, 1 Oct 2021 08:15:12 +0800 Subject: [PATCH] iscsi-support: fix memory leak If doesn't support the report_supported_opcodes, the task will not be freed in REPORT_SUPPORTED_OPCODES. Change-Id: I1e251eec518721fb35e51013621aa61865d4b46b Signed-off-by: Li Feng --- test-tool/iscsi-support.c | 2 +- test-tool/iscsi-test-cu.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 5a30a76..9363140 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -2130,7 +2130,7 @@ int report_supported_opcodes(struct scsi_device *sdev, struct scsi_task **out_ta task = send_scsi_command(sdev, task, NULL); ret = check_result("REPORT_SUPPORTED_OPCODES", sdev, task, status, key, ascq, num_ascq); - if (out_task) { + if (out_task && ret != -2 /* Not Supported */) { *out_task = task; } else if (task) { scsi_free_scsi_task(task); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 2b70687..4e14913 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -1448,13 +1448,14 @@ main(int argc, char *argv[]) } rsop_task = NULL; - report_supported_opcodes(sd, &rsop_task, 1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535, + res = report_supported_opcodes(sd, &rsop_task, 1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535, EXPECT_STATUS_GOOD); - if (rsop_task == NULL) { + if (res == -2) { + printf("Unsupport the REPORT_SUPPORTED_OPCODES\n"); + } else if (rsop_task == NULL) { printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n", sd->error_str); goto err_sds_free; - } - if (rsop_task->status == SCSI_STATUS_GOOD) { + } else if (rsop_task->status == SCSI_STATUS_GOOD) { rsop = scsi_datain_unmarshall(rsop_task); if (rsop == NULL) { printf("failed to unmarshall REPORT_SUPPORTED_OPCODES data.\n");