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:
Ziye Yang 2016-06-07 10:19:06 +08:00 committed by Daniel Verkamp
parent 7991eb1957
commit 450bb7605b
2 changed files with 8 additions and 11 deletions

View File

@ -118,14 +118,14 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
}
p++;
n = p - listen_addr;
*host = malloc(n + 1);
*host = calloc(1, n + 1);
if (!*host) {
return -1;
}
memcpy(*host, listen_addr, n);
(*host)[n] = '\0';
if (p[0] == '\0') {
*port = malloc(PORTNUMSTRLEN);
*port = calloc(1, PORTNUMSTRLEN);
if (!*port) {
free(*host);
return -1;
@ -142,12 +142,11 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
}
len = q - p - 1;
*port = malloc(len + 1);
*port = calloc(1, len + 1);
if (!*port) {
free(*host);
return -1;
}
memset(*port, 0, len + 1);
memcpy(*port, p + 1, len);
}
} else {
@ -157,14 +156,14 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
p = listen_addr + strlen(listen_addr);
}
n = p - listen_addr;
*host = malloc(n + 1);
*host = calloc(1, n + 1);
if (!*host) {
return -1;
}
memcpy(*host, listen_addr, n);
(*host)[n] = '\0';
if (p[0] == '\0') {
*port = malloc(PORTNUMSTRLEN);
*port = calloc(1, PORTNUMSTRLEN);
if (!*port) {
free(*host);
return -1;
@ -186,12 +185,11 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
}
len = q - p - 1;
*port = malloc(len + 1);
*port = calloc(1, len + 1);
if (!*port) {
free(*host);
return -1;
}
memset(*port, 0, len + 1);
memcpy(*port, p + 1, len);
}

View File

@ -53,10 +53,9 @@ nvmf_create_session(const char *subnqn)
if (subsystem == NULL)
return NULL;
session = malloc(sizeof(struct nvmf_session));
session = calloc(1, sizeof(struct nvmf_session));
if (session == NULL)
goto exit;
memset(session, 0, sizeof(struct nvmf_session));
subsystem->num_sessions++;
/* define cntlid that is unique across all subsystems */
@ -235,7 +234,7 @@ nvmf_connect(void *fabric_conn,
struct nvmf_session *session;
struct nvmf_connection_entry *connection = NULL;
connection = malloc(sizeof(struct nvmf_connection_entry));
connection = calloc(1, sizeof(struct nvmf_connection_entry));
if (connection == NULL)
goto connect_fail;