From 264ea509c8e1befa517606ab540a2bff3117684b Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 21 Sep 2014 15:14:51 -0700 Subject: [PATCH] iscsi-support.c: fix memory leaks. Thanks valgrind, you rock Signed-off-by: Ronnie Sahlberg --- test-tool/iscsi-support.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index ca1ea8d..7569983 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -235,6 +235,9 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi io_hdr.timeout = 5000; if(ioctl(sdev->sgio_fd, SG_IO, &io_hdr) < 0){ + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } sdev->error_str = strdup("SG_IO ioctl failed"); return NULL; } @@ -261,6 +264,9 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.key, scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq); + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } sdev->error_str = strdup(buf); return task; } @@ -270,6 +276,9 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.key = 0x0f; task->sense.ascq = 0xffff; + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } sdev->error_str = strdup("SCSI masked error"); return NULL; } @@ -279,6 +288,9 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.ascq = 0xffff; snprintf(buf, sizeof(buf), "SCSI host error. Status=0x%x", io_hdr.host_status); + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } sdev->error_str = strdup(buf); return task; } @@ -287,6 +299,9 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.key = 0x0f; task->sense.ascq = 0xffff; + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } sdev->error_str = strdup("SCSI driver error"); return NULL; }