@@ -351,6 +351,7 @@ void* iscsi_zmalloc(struct iscsi_context *iscsi, size_t size);
|
|||||||
void* iscsi_realloc(struct iscsi_context *iscsi, void* ptr, size_t size);
|
void* iscsi_realloc(struct iscsi_context *iscsi, void* ptr, size_t size);
|
||||||
void iscsi_free(struct iscsi_context *iscsi, void* ptr);
|
void iscsi_free(struct iscsi_context *iscsi, void* ptr);
|
||||||
char* iscsi_strdup(struct iscsi_context *iscsi, const char* str);
|
char* iscsi_strdup(struct iscsi_context *iscsi, const char* str);
|
||||||
|
void* iscsi_smalloc(struct iscsi_context *iscsi, size_t size);
|
||||||
void* iscsi_szmalloc(struct iscsi_context *iscsi, size_t size);
|
void* iscsi_szmalloc(struct iscsi_context *iscsi, size_t size);
|
||||||
void iscsi_sfree(struct iscsi_context *iscsi, void* ptr);
|
void iscsi_sfree(struct iscsi_context *iscsi, void* ptr);
|
||||||
|
|
||||||
|
|||||||
13
lib/init.c
13
lib/init.c
@@ -111,15 +111,22 @@ char* iscsi_strdup(struct iscsi_context *iscsi, const char* str) {
|
|||||||
return str2;
|
return str2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* iscsi_szmalloc(struct iscsi_context *iscsi, size_t size) {
|
void* iscsi_smalloc(struct iscsi_context *iscsi, size_t size) {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
if (size > iscsi->smalloc_size) return NULL;
|
if (size > iscsi->smalloc_size) return NULL;
|
||||||
if (iscsi->smalloc_free > 0) {
|
if (iscsi->smalloc_free > 0) {
|
||||||
ptr = iscsi->smalloc_ptrs[--iscsi->smalloc_free];
|
ptr = iscsi->smalloc_ptrs[--iscsi->smalloc_free];
|
||||||
memset(ptr, 0, iscsi->smalloc_size);
|
|
||||||
iscsi->smallocs++;
|
iscsi->smallocs++;
|
||||||
} else {
|
} else {
|
||||||
ptr = iscsi_zmalloc(iscsi, iscsi->smalloc_size);
|
ptr = iscsi_malloc(iscsi, iscsi->smalloc_size);
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* iscsi_szmalloc(struct iscsi_context *iscsi, size_t size) {
|
||||||
|
void *ptr = iscsi_smalloc(iscsi, size);
|
||||||
|
if (ptr) {
|
||||||
|
memset(ptr, 0, size);
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user