From 389f6a8ba5df38405a18271987758a6c279ad65e Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Wed, 31 Oct 2012 16:46:33 +0100 Subject: [PATCH] SCSI half mallocs in scsi_malloc --- lib/scsi-lowlevel.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index 3787072..3f8020e 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -47,7 +47,6 @@ scsi_free_scsi_task(struct scsi_task *task) while ((mem = task->mem)) { SLIST_REMOVE(&task->mem, mem); - free(mem->ptr); free(mem); } @@ -60,17 +59,12 @@ scsi_malloc(struct scsi_task *task, size_t size) { struct scsi_allocated_memory *mem; - mem = malloc(sizeof(struct scsi_allocated_memory)); + mem = malloc(sizeof(struct scsi_allocated_memory) + size); if (mem == NULL) { return NULL; } - memset(mem, 0, sizeof(struct scsi_allocated_memory)); - mem->ptr = malloc(size); - if (mem->ptr == NULL) { - free(mem); - return NULL; - } - memset(mem->ptr, 0, size); + memset(mem, 0, sizeof(struct scsi_allocated_memory) + size); + mem->ptr = (void *) ((uintptr_t)mem + sizeof(struct scsi_allocated_memory)); SLIST_ADD(&task->mem, mem); return mem->ptr; }