From 9df32565a665a421bf57863b31e600c770dfdb06 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 23 Jan 2017 10:46:14 -0800 Subject: [PATCH] test-tool/test_async_read.c: Allocate large arrays dynamically This patch avoids that Valgrind complains about the memset() call that was used to initialize the array that it triggers an invalid write. Signed-off-by: Bart Van Assche --- test-tool/test_async_read.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test-tool/test_async_read.c b/test-tool/test_async_read.c index 5d0e155..45850ac 100644 --- a/test-tool/test_async_read.c +++ b/test-tool/test_async_read.c @@ -60,27 +60,29 @@ test_async_read(void) { int i, ret; struct tests_async_read_state state = { 0, 0, 0 }; - int blocksize = 512; - int blocks_per_io = 8; - int num_ios = 1000; + const int blocksize = 512; + const int blocks_per_io = 8; + const int num_ios = 1000; /* IOs in flight concurrently, so need a buffer large enough for all */ - unsigned char buf[blocksize * blocks_per_io * num_ios]; + unsigned char *buf = calloc(blocksize * blocks_per_io, num_ios); + + CU_ASSERT_NOT_EQUAL(buf, NULL); + if (!buf) + goto out; CHECK_FOR_DATALOSS; CHECK_FOR_SBC; if (sd->iscsi_ctx == NULL) { CU_PASS("[SKIPPED] Non-iSCSI"); - return; + goto out; } if (maximum_transfer_length && (maximum_transfer_length < (blocks_per_io * num_ios))) { CU_PASS("[SKIPPED] device too small for async_read test"); - return; + goto out; } - memset(buf, 0, blocksize * blocks_per_io * num_ios); - for (i = 0; i < num_ios; i++) { uint32_t lba = i * blocks_per_io; struct scsi_task *atask; @@ -116,4 +118,7 @@ test_async_read(void) ret = iscsi_service(sd->iscsi_ctx, pfd.revents); CU_ASSERT_EQUAL(ret, 0); } + +out: + free(buf); }