lib: Make scsi_free_scsi_task() accept a NULL task pointer

Several cleanup paths can be simplified if it is allowed to pass a
NULL pointer to scsi_free_scsi_task(). Hence modify this function
such that it returns immediately if passed a NULL task pointer.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
lib: Fix a memory leak in scsi_cdb_persistent_reserve_out()

If scsi_cdb_persistent_reserve_out() succeeds a call to
scsi_free_scsi_task() won't free any memory allocated with scsi_malloc()
in this function because the memset() call in this function overwrites
the task->mem pointer. Move the memset() call up such that it doesn't
clear task->mem. This makes it possible for the caller of this function
to free the memory allocated by this function by calling
scsi_free_scsi_task(). Merge the error handling code such that the code
for freeing memory only occurs once.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool, RESERVE(6) tests: Avoid leaking 'iscsi2'

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool, WRITESAME(16) UNMAP test: Avoid leaking 'buf' if a precondition fails

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in testunitready_clear_ua()

Avoid leaking 'task' if task->status != SCSI_STATUS_GOOD.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in test_preventallow_logout.c

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in test-tool/test_reserve6_logout.c

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix memory leaks in test setup and teardown functions

Free read_write_buf and task after each test. Free iscsi2 after
each PGR test when using CUnit version 2. Note: CUnit version 1
doesn't support test setup and teardown functions.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in test_reserve6_lun_reset.c

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Add two additional READ16-beyond-eol tests

This helps testing SCSI target implementations that represent the
byte offset from the start of the device as a signed or unsigned
64-bit integer.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test-tool/0184_writesame10_0blocks.c: Include WSNZ bit in test

Signed-off-by: Bart Van Assche <bvanassche@acm.org>