From 9ab1cc8baa6f3ad3a532687919402fe98e1a54e8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 6 Oct 2015 15:18:46 -0700 Subject: [PATCH] test-tool/*_dpofua: Fix memory leaks in error paths Signed-off-by: Bart Van Assche --- test-tool/test_compareandwrite_dpofua.c | 4 +++- test-tool/test_orwrite_dpofua.c | 4 +++- test-tool/test_read10_dpofua.c | 4 +++- test-tool/test_read12_dpofua.c | 4 +++- test-tool/test_read16_dpofua.c | 4 +++- .../test_report_supported_opcodes_one_command.c | 13 +++++-------- test-tool/test_report_supported_opcodes_rctd.c | 17 +++++++---------- .../test_report_supported_opcodes_servactv.c | 12 +++++------- test-tool/test_verify10_dpo.c | 4 +++- test-tool/test_verify12_dpo.c | 4 +++- test-tool/test_verify16_dpo.c | 4 +++- test-tool/test_write10_dpofua.c | 4 +++- test-tool/test_write12_dpofua.c | 4 +++- test-tool/test_write16_dpofua.c | 4 +++- test-tool/test_writeatomic16_dpofua.c | 4 +++- test-tool/test_writeverify10_dpo.c | 4 +++- test-tool/test_writeverify12_dpo.c | 4 +++- test-tool/test_writeverify16_dpo.c | 4 +++- 18 files changed, 62 insertions(+), 40 deletions(-) diff --git a/test-tool/test_compareandwrite_dpofua.c b/test-tool/test_compareandwrite_dpofua.c index 329aca8..c8fe34f 100644 --- a/test-tool/test_compareandwrite_dpofua.c +++ b/test-tool/test_compareandwrite_dpofua.c @@ -123,7 +123,7 @@ test_compareandwrite_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -152,5 +152,7 @@ test_compareandwrite_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_orwrite_dpofua.c b/test-tool/test_orwrite_dpofua.c index d460682..3ddfd57 100644 --- a/test-tool/test_orwrite_dpofua.c +++ b/test-tool/test_orwrite_dpofua.c @@ -120,7 +120,7 @@ test_orwrite_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -149,5 +149,7 @@ test_orwrite_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_read10_dpofua.c b/test-tool/test_read10_dpofua.c index 127e01a..7f3de8f 100644 --- a/test-tool/test_read10_dpofua.c +++ b/test-tool/test_read10_dpofua.c @@ -108,7 +108,7 @@ test_read10_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -137,5 +137,7 @@ test_read10_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_read12_dpofua.c b/test-tool/test_read12_dpofua.c index a401138..a0d89e6 100644 --- a/test-tool/test_read12_dpofua.c +++ b/test-tool/test_read12_dpofua.c @@ -107,7 +107,7 @@ test_read12_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -136,5 +136,7 @@ test_read12_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_read16_dpofua.c b/test-tool/test_read16_dpofua.c index c649158..8eb7930 100644 --- a/test-tool/test_read16_dpofua.c +++ b/test-tool/test_read16_dpofua.c @@ -108,7 +108,7 @@ test_read16_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -137,5 +137,7 @@ test_read16_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_report_supported_opcodes_one_command.c b/test-tool/test_report_supported_opcodes_one_command.c index c6d0832..4eb91df 100644 --- a/test-tool/test_report_supported_opcodes_one_command.c +++ b/test-tool/test_report_supported_opcodes_one_command.c @@ -47,14 +47,11 @@ test_report_supported_opcodes_one_command(void) logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); CU_PASS("READ_SUPPORTED_OPCODES is not implemented."); - scsi_free_scsi_task(rso_task); - return; + goto out; } CU_ASSERT_EQUAL(ret, 0); - if (ret != 0) { - scsi_free_scsi_task(rso_task); - return; - } + if (ret != 0) + goto out; logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -64,7 +61,7 @@ test_report_supported_opcodes_one_command(void) "for ReportSupportedOpcodes\n"); CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); - return; + goto out; } logging(LOG_VERBOSE, "Verify read one-command works for all supported " @@ -200,6 +197,6 @@ test_report_supported_opcodes_one_command(void) scsi_free_scsi_task(one_task); } - +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_report_supported_opcodes_rctd.c b/test-tool/test_report_supported_opcodes_rctd.c index 99b152f..43933f2 100644 --- a/test-tool/test_report_supported_opcodes_rctd.c +++ b/test-tool/test_report_supported_opcodes_rctd.c @@ -47,14 +47,11 @@ test_report_supported_opcodes_rctd(void) logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); CU_PASS("READ_SUPPORTED_OPCODES is not implemented."); - scsi_free_scsi_task(rso_task); - return; + goto out; } CU_ASSERT_EQUAL(ret, 0); - if (ret != 0) { - scsi_free_scsi_task(rso_task); - return; - } + if (ret != 0) + goto out; logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -64,7 +61,7 @@ test_report_supported_opcodes_rctd(void) "for ReportSupportedOpcodes\n"); CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); - return; + goto out; } logging(LOG_VERBOSE, "Verify that all returned command descriptors " @@ -89,9 +86,8 @@ test_report_supported_opcodes_rctd(void) 65535, EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - if (ret != 0) { - return; - } + if (ret != 0) + goto out; logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -120,5 +116,6 @@ test_report_supported_opcodes_rctd(void) } } +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_report_supported_opcodes_servactv.c b/test-tool/test_report_supported_opcodes_servactv.c index d327c83..0a7f968 100644 --- a/test-tool/test_report_supported_opcodes_servactv.c +++ b/test-tool/test_report_supported_opcodes_servactv.c @@ -45,14 +45,11 @@ test_report_supported_opcodes_servactv(void) logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); CU_PASS("READ_SUPPORTED_OPCODES is not implemented."); - scsi_free_scsi_task(rso_task); - return; + goto out; } CU_ASSERT_EQUAL(ret, 0); - if (ret != 0) { - scsi_free_scsi_task(rso_task); - return; - } + if (ret != 0) + goto out; logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -62,7 +59,7 @@ test_report_supported_opcodes_servactv(void) "for ReportSupportedOpcodes\n"); CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); - return; + goto out; } @@ -77,5 +74,6 @@ test_report_supported_opcodes_servactv(void) } } +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_verify10_dpo.c b/test-tool/test_verify10_dpo.c index 9f7abe4..cd65fbd 100644 --- a/test-tool/test_verify10_dpo.c +++ b/test-tool/test_verify10_dpo.c @@ -97,7 +97,7 @@ test_verify10_dpo(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -112,5 +112,7 @@ test_verify10_dpo(void) "flag is clear in the CDB_USAGE_DATA"); CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_verify12_dpo.c b/test-tool/test_verify12_dpo.c index f3976d2..94a913f 100644 --- a/test-tool/test_verify12_dpo.c +++ b/test-tool/test_verify12_dpo.c @@ -97,7 +97,7 @@ test_verify12_dpo(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -112,5 +112,7 @@ test_verify12_dpo(void) "flag is clear in the CDB_USAGE_DATA"); CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_verify16_dpo.c b/test-tool/test_verify16_dpo.c index 66b9d32..fcc2e86 100644 --- a/test-tool/test_verify16_dpo.c +++ b/test-tool/test_verify16_dpo.c @@ -97,7 +97,7 @@ test_verify16_dpo(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -112,5 +112,7 @@ test_verify16_dpo(void) "flag is clear in the CDB_USAGE_DATA"); CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_write10_dpofua.c b/test-tool/test_write10_dpofua.c index 870feff..2a38889 100644 --- a/test-tool/test_write10_dpofua.c +++ b/test-tool/test_write10_dpofua.c @@ -111,7 +111,7 @@ test_write10_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -140,5 +140,7 @@ test_write10_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_write12_dpofua.c b/test-tool/test_write12_dpofua.c index 05f0511..9104924 100644 --- a/test-tool/test_write12_dpofua.c +++ b/test-tool/test_write12_dpofua.c @@ -121,7 +121,7 @@ test_write12_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -150,5 +150,7 @@ test_write12_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_write16_dpofua.c b/test-tool/test_write16_dpofua.c index 4d2c5a0..9eb93d4 100644 --- a/test-tool/test_write16_dpofua.c +++ b/test-tool/test_write16_dpofua.c @@ -121,7 +121,7 @@ test_write16_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -150,5 +150,7 @@ test_write16_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeatomic16_dpofua.c b/test-tool/test_writeatomic16_dpofua.c index 87b0ff7..a10b54d 100644 --- a/test-tool/test_writeatomic16_dpofua.c +++ b/test-tool/test_writeatomic16_dpofua.c @@ -129,7 +129,7 @@ test_writeatomic16_dpofua(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -158,5 +158,7 @@ test_writeatomic16_dpofua(void) CU_FAIL("Target did not return any data for " "ReportSupportedOpcodes"); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeverify10_dpo.c b/test-tool/test_writeverify10_dpo.c index 1c30e4d..285041a 100644 --- a/test-tool/test_writeverify10_dpo.c +++ b/test-tool/test_writeverify10_dpo.c @@ -97,7 +97,7 @@ test_writeverify10_dpo(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -112,5 +112,7 @@ test_writeverify10_dpo(void) "flag is clear in the CDB_USAGE_DATA"); CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeverify12_dpo.c b/test-tool/test_writeverify12_dpo.c index 068d516..9233c59 100644 --- a/test-tool/test_writeverify12_dpo.c +++ b/test-tool/test_writeverify12_dpo.c @@ -97,7 +97,7 @@ test_writeverify12_dpo(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -112,5 +112,7 @@ test_writeverify12_dpo(void) "flag is clear in the CDB_USAGE_DATA"); CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } + +out: scsi_free_scsi_task(rso_task); } diff --git a/test-tool/test_writeverify16_dpo.c b/test-tool/test_writeverify16_dpo.c index 3ce4c7b..1dccc0a 100644 --- a/test-tool/test_writeverify16_dpo.c +++ b/test-tool/test_writeverify16_dpo.c @@ -99,7 +99,7 @@ test_writeverify16_dpo(void) if (ret == -2) { logging(LOG_NORMAL, "REPORT_SUPPORTED_OPCODES not implemented. " "Skipping this part of the test"); - return; + goto out; } logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc = scsi_datain_unmarshall(rso_task); @@ -114,5 +114,7 @@ test_writeverify16_dpo(void) "flag is clear in the CDB_USAGE_DATA"); CU_ASSERT_EQUAL(usage_data_dpo, 0x00); } + +out: scsi_free_scsi_task(rso_task); }