nvme: Cleanup resources when memory allocation fails

Several resources remain allocated when malloc fails.

Change-Id: I2b6df59978100833a91915c3267f3a54f6fc0de4
Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1336
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Alexey Marchuk 2020-03-17 19:26:01 +03:00 committed by Tomasz Zawadzki
parent c0db2b6d6a
commit a843098732
2 changed files with 7 additions and 1 deletions

View File

@ -548,6 +548,7 @@ static int nvme_ctrlr_set_intel_support_log_pages(struct spdk_nvme_ctrlr *ctrlr)
status = malloc(sizeof(*status));
if (!status) {
SPDK_ERRLOG("Failed to allocate status tracker\n");
spdk_free(log_page_directory);
return -ENOMEM;
}
@ -1312,6 +1313,7 @@ nvme_ctrlr_identify_active_ns(struct spdk_nvme_ctrlr *ctrlr)
status = malloc(sizeof(*status));
if (!status) {
SPDK_ERRLOG("Failed to allocate status tracker\n");
spdk_free(new_ns_list);
return -ENOMEM;
}
@ -2989,7 +2991,7 @@ spdk_nvme_ctrlr_create_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns_dat
status = malloc(sizeof(*status));
if (!status) {
SPDK_ERRLOG("Failed to allocate status tracker\n");
return -ENOMEM;
return 0;
}
res = nvme_ctrlr_cmd_create_ns(ctrlr, payload, nvme_completion_poll_cb, status);

View File

@ -297,6 +297,7 @@ nvme_fabric_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
status = malloc(sizeof(*status));
if (!status) {
SPDK_ERRLOG("Failed to allocate status tracker\n");
nvme_ctrlr_destruct(discovery_ctrlr);
return -ENOMEM;
}
@ -306,12 +307,14 @@ nvme_fabric_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
nvme_completion_poll_cb, status);
if (rc != 0) {
SPDK_ERRLOG("Failed to identify cdata\n");
nvme_ctrlr_destruct(discovery_ctrlr);
free(status);
return rc;
}
if (spdk_nvme_wait_for_completion(discovery_ctrlr->adminq, status)) {
SPDK_ERRLOG("nvme_identify_controller failed!\n");
nvme_ctrlr_destruct(discovery_ctrlr);
if (!status->timed_out) {
free(status);
}
@ -413,6 +416,7 @@ nvme_fabric_qpair_connect(struct spdk_nvme_qpair *qpair, uint32_t num_entries)
status = malloc(sizeof(*status));
if (!status) {
SPDK_ERRLOG("Failed to allocate status tracker\n");
spdk_free(nvmf_data);
return -ENOMEM;
}