SCSI half mallocs in scsi_malloc

This commit is contained in:
Peter Lieven
2012-10-31 16:46:33 +01:00
parent 1d348de71f
commit 389f6a8ba5

View File

@@ -47,7 +47,6 @@ scsi_free_scsi_task(struct scsi_task *task)
while ((mem = task->mem)) { while ((mem = task->mem)) {
SLIST_REMOVE(&task->mem, mem); SLIST_REMOVE(&task->mem, mem);
free(mem->ptr);
free(mem); free(mem);
} }
@@ -60,17 +59,12 @@ scsi_malloc(struct scsi_task *task, size_t size)
{ {
struct scsi_allocated_memory *mem; struct scsi_allocated_memory *mem;
mem = malloc(sizeof(struct scsi_allocated_memory)); mem = malloc(sizeof(struct scsi_allocated_memory) + size);
if (mem == NULL) { if (mem == NULL) {
return NULL; return NULL;
} }
memset(mem, 0, sizeof(struct scsi_allocated_memory)); memset(mem, 0, sizeof(struct scsi_allocated_memory) + size);
mem->ptr = malloc(size); mem->ptr = (void *) ((uintptr_t)mem + sizeof(struct scsi_allocated_memory));
if (mem->ptr == NULL) {
free(mem);
return NULL;
}
memset(mem->ptr, 0, size);
SLIST_ADD(&task->mem, mem); SLIST_ADD(&task->mem, mem);
return mem->ptr; return mem->ptr;
} }