nvmf: replace all malloc with calloc in nvmf library
Change-Id: Ibf6719996ef683d8efc82068b2294ce0f75c54f9 Signed-off-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
parent
7991eb1957
commit
450bb7605b
@ -118,14 +118,14 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
|
|||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
n = p - listen_addr;
|
n = p - listen_addr;
|
||||||
*host = malloc(n + 1);
|
*host = calloc(1, n + 1);
|
||||||
if (!*host) {
|
if (!*host) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(*host, listen_addr, n);
|
memcpy(*host, listen_addr, n);
|
||||||
(*host)[n] = '\0';
|
(*host)[n] = '\0';
|
||||||
if (p[0] == '\0') {
|
if (p[0] == '\0') {
|
||||||
*port = malloc(PORTNUMSTRLEN);
|
*port = calloc(1, PORTNUMSTRLEN);
|
||||||
if (!*port) {
|
if (!*port) {
|
||||||
free(*host);
|
free(*host);
|
||||||
return -1;
|
return -1;
|
||||||
@ -142,12 +142,11 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
|
|||||||
}
|
}
|
||||||
len = q - p - 1;
|
len = q - p - 1;
|
||||||
|
|
||||||
*port = malloc(len + 1);
|
*port = calloc(1, len + 1);
|
||||||
if (!*port) {
|
if (!*port) {
|
||||||
free(*host);
|
free(*host);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(*port, 0, len + 1);
|
|
||||||
memcpy(*port, p + 1, len);
|
memcpy(*port, p + 1, len);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -157,14 +156,14 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
|
|||||||
p = listen_addr + strlen(listen_addr);
|
p = listen_addr + strlen(listen_addr);
|
||||||
}
|
}
|
||||||
n = p - listen_addr;
|
n = p - listen_addr;
|
||||||
*host = malloc(n + 1);
|
*host = calloc(1, n + 1);
|
||||||
if (!*host) {
|
if (!*host) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(*host, listen_addr, n);
|
memcpy(*host, listen_addr, n);
|
||||||
(*host)[n] = '\0';
|
(*host)[n] = '\0';
|
||||||
if (p[0] == '\0') {
|
if (p[0] == '\0') {
|
||||||
*port = malloc(PORTNUMSTRLEN);
|
*port = calloc(1, PORTNUMSTRLEN);
|
||||||
if (!*port) {
|
if (!*port) {
|
||||||
free(*host);
|
free(*host);
|
||||||
return -1;
|
return -1;
|
||||||
@ -186,12 +185,11 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = q - p - 1;
|
len = q - p - 1;
|
||||||
*port = malloc(len + 1);
|
*port = calloc(1, len + 1);
|
||||||
if (!*port) {
|
if (!*port) {
|
||||||
free(*host);
|
free(*host);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(*port, 0, len + 1);
|
|
||||||
memcpy(*port, p + 1, len);
|
memcpy(*port, p + 1, len);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,9 @@ nvmf_create_session(const char *subnqn)
|
|||||||
if (subsystem == NULL)
|
if (subsystem == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
session = malloc(sizeof(struct nvmf_session));
|
session = calloc(1, sizeof(struct nvmf_session));
|
||||||
if (session == NULL)
|
if (session == NULL)
|
||||||
goto exit;
|
goto exit;
|
||||||
memset(session, 0, sizeof(struct nvmf_session));
|
|
||||||
|
|
||||||
subsystem->num_sessions++;
|
subsystem->num_sessions++;
|
||||||
/* define cntlid that is unique across all subsystems */
|
/* define cntlid that is unique across all subsystems */
|
||||||
@ -235,7 +234,7 @@ nvmf_connect(void *fabric_conn,
|
|||||||
struct nvmf_session *session;
|
struct nvmf_session *session;
|
||||||
struct nvmf_connection_entry *connection = NULL;
|
struct nvmf_connection_entry *connection = NULL;
|
||||||
|
|
||||||
connection = malloc(sizeof(struct nvmf_connection_entry));
|
connection = calloc(1, sizeof(struct nvmf_connection_entry));
|
||||||
if (connection == NULL)
|
if (connection == NULL)
|
||||||
goto connect_fail;
|
goto connect_fail;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user